我正在尝试测试 IInterceptionBehavior 的实现:
public class LoggingInterceptorBehavior : IInterceptionBehavior
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var methodBase = input.MethodBase;
/* ... */
return getNext()(input, getNext);
}
public IEnumerable<Type> GetRequiredInterfaces() { /* ... */ }
public bool WillExecute { get { return true; } }
}
我怎样才能创建一个假的 MethodBase?
请您参考如下方法:
技巧似乎是,相当复杂地,使用反射获取 MethodHandle,然后将其传递到 MethodBase 类的静态方法中:
var methodHandle = dummyClass.GetType().GetMethod("dummyMethod").MethodHandle;
var methodBase = MethodBase.GetMethodFromHandle(methodHandle);
