nickdodd79 / AutoBogus

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

Feature request: generate from non-generic type (so with Type parameter) #107

Closed 304NotModified closed 1 year ago

304NotModified commented 1 year ago

I would like to generate from a Type parameter,

e.g.

Type type = ...
object generateObject = new AutoFaker(type).Generate(); 

Current work around:

Type type = ...
Type autoFakerType = typeof(AutoFaker<>).MakeGenericType(type);
dynamic autoFaker = Activator.CreateInstance(autoFakerType) ?? throw new Exception($"Failed creating type {autoFakerType.FullName} gefaald");
object generateObject = autoFaker.Generate();

Is a PR accepted for this? (needs some refactoring to replace internal calls from generic to non-generic)

This is maybe the same question: https://github.com/nickdodd79/AutoBogus/issues/98

304NotModified commented 1 year ago

Ah! Duplicate of https://github.com/nickdodd79/AutoBogus/issues/75