Open gkruszewski opened 2 years ago
Hey @gkruszewski
Shouldn't be difficult to add non-generic support. I will see what I can do.
Nick.
This is the basic approach I've been playing around with:
var client1 = new AutoFaker<Client>().Generate();
is equivalent to:
var fakerType = typeof(AutoFaker<>).MakeGenericType(new[]{typeof(Client)});
var faker = Activator.CreateInstance(fakerType);
var client1 = fakerType.GetMethod("Generate", new[] { typeof(string) }).Invoke(faker, new object?[] { null});
I was about to open the same issue. Please expose such API, though MakeGenericMethod
approach works, it's better to have it without using reflection.
@nickdodd79 , would you accept such PR to AutoGenerateContextExtensions
?
public static object Generate(this AutoGenerateContext context,Type typeToGenerate)
{
if (context != null)
{
// Set the generate type for the current request
context.GenerateType =typeToGenerate;
// Get the type generator and return a value
var generator = AutoGeneratorFactory.GetGenerator(context);
return generator.Generate(context);
}
return default;
}
+1 for this. I need this for unit testing where you have a [Theory]
This is a very, very interesting feature request ! May I ask what's the status :) ?
@NinjaCross I think this project is abandoned.
Not to worry though!
I recently added this non-type parameter feature to soenneker.utils.autobogus
Thankyou @soenneker !
Can we add static non-generic counterparts for the
Generate
methods that accept aType
to theAutoFaker
class?