nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
423 stars 49 forks source link

Is it possible to generate weakly-typed objects? #98

Closed vbreuss closed 1 year ago

vbreuss commented 1 year ago

I would like to use AutoBogus to automatically generate an object, but I only have the Type information and cannot apply the generic constraint.

Would it be possible to provide an overload like

public static object Generate(Type type, Action<IAutoGenerateConfigBuilder> configure = null);

which will generate an object of type type?

Background: I tried to implement something like the AutoDataAttribute but using AutoBogus to generate the objects. But I only get a ParameterInfo and would need to create an object from the weakly-typed ParameterType information.

I couldn't find any example neither here nor in Bogus directly. Is this simply not possible?