【发布时间】:2009-05-18 15:36:02
【问题描述】:
我看不到这段代码失败的原因(绑定到目标方法时出错。)
public interface Interface
{}
public class Implementation : Interface
{}
public class Program
{
public static void Main()
{
Invoke();
}
public Interface SomeMethod(object arg)
{
return new Implementation();
}
public void Invoke()
{
Delegate someMethod = Delegate.CreateDelegate(typeof(Func<Interface, object>), this, "SomeMethod");
}
}
尝试了不同的 CreateDelegate 重载,结果相同:当目标方法返回接口类型时,将委托绑定到方法失败。 任何人都可以对此有所了解吗?
【问题讨论】: