委托不包含“ CreateDelegate”的定义

时间:2018-11-06 12:53:19

标签: c# unity3d uwp

使用Unity 2018-2017在构建网络  错误CS0117:“ Delegate”不包含“ CreateDelegate”的定义 这是方法:

 private V CreateDelegate<V>(MethodInfo method, Object target) where V : class
    {

        var ret = (Delegate.CreateDelegate(typeof(V), target, method) as V);

        if (ret == null)
        {
            throw new ArgumentException("Unabled to create delegate for method called " + method.Name);
        }
        return ret;

    }

UWP构建。 使用system.Linq 我尝试使用“ MethodInfo”,但可能某些参数错误。 无法使用此方法吗?

2 个答案:

答案 0 :(得分:0)

您要定位哪个平台/运行时间?我不了解Mono,但是.Net标准1.x不支持Delegate.CreateDelegate。请始终记住,您是针对.Net框架的有限子集编写代码的。另外请记住,您的代码将不可避免地在某些平台(il2cpp,iOS等)上进行AOT编译,因此某些反射/发射功能将不可用。

注意:AOT意味着提前,这意味着您的代码被编译为机器指令,而不是中间语言。反射是将代码本身用作数据时的情况,例如,您可以获取类定义的属性的列表。发出意味着在运行时生成代码。如果您不了解这些内容,则可能应该做一些研究。从长远来看,这是值得的。

答案 1 :(得分:0)

1。您的返回类型是一个类,而不是委托。

where V : class

所以这种方法甚至没有意义。您将获得无效的强制转换异常。

2。 CreateDelegate接受2个参数,而不是3个。

我什至不知道target的目的是什么,所以我什至无法猜测您要做什么。

相关问题