是否可以通过反射编写以下代码?
var fake = A.Fake<Foo>(
o => o.WithArgumentsForConstructor(new[] { "Hello" }));
其中o是:
Action<IFakeOptionsBuilder<T>>
WithArgumentsForConstructor在哪里:
IFakeOptionsBuilder<T> WithArgumentsForConstructor(IEnumerable<object> argumentsForConstructor);
Foo 类是:
class Foo
{
public Foo(string s)
{
}
}
我所做的是:
object fake = typeof(A)
.GetMethod("Fake", new Type[] { })
.MakeGenericMethod(new[] { this.targetType })
.Invoke(null, /* Here I need to pass the lambda. */);