返回类型为interface时,Delegate.CreateDelegate失败

0 .net c# delegates

我没有看到此代码失败的原因(绑定到目标方法的错误.)

    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");
      }
    }
Run Code Online (Sandbox Code Playgroud)

尝试使用相同结果的CreateDelegate的不同重载:当目标方法返回接口类型时,将委托绑定到方法失败.任何人都可以对此有所了解吗?

the*_*tar 7

你的模板参数是倒退的,它应该是 Func<object,Interface>