Is it possible to write the following code via Reflection?
var fake = A.Fake<Foo>(
o => o.WithArgumentsForConstructor(new[] { "Hello" }));
Where o is:
Action<IFakeOptionsBuilder<T>>
Where WithArgumentsForConstructor is:
IFakeOptionsBuilder<T> WithArgumentsForConstructor(IEnumerable<object> argumentsForConstructor);
The Foo class is:
class Foo
{
public Foo(string s)
{
}
}
What I did was:
object fake = typeof(A)
.GetMethod("Fake", new Type[] { })
.MakeGenericMethod(new[] { this.targetType })
.Invoke(null, /* Here I need to pass the lambda. */);
Yes, it is possible to do what you suggest via reflection, however quite unnecessary. It would be simpler to define a static method yourself like this:
Now simply call this function using reflection: