LambdaExpression CompileToMethod

非 Y 不嫁゛ 提交于 2020-01-21 12:17:29

问题


I Have a few lines of code

public void CreateMethod<TContract>(Expression<Action<TContract>> method)
{
   var innerMethod = Builder.DefineMethod("SomeName",MethodAttributes.Private);
   method.CompileToMethod(innerMethod);
   //more code
}

However the second line fails. I've tried with different versions of DefineMethod with little luck. Any suggestions?


回答1:


Unfortunately, CompileToMethod requires a static method as its argument (see here). Therefore, you need to add MethodAttributes.Static to innerMethod's definition.



来源:https://stackoverflow.com/questions/3992376/lambdaexpression-compiletomethod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!