LambdaEx pression CompileToMethod [英] LambdaExpression CompileToMethod

查看:307
本文介绍了LambdaEx pression CompileToMethod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code的几行

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

不过第二行失败。我试着用一点运气不同DefineMethod版本。 有什么建议?

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

推荐答案

不幸的是, CompileToMethod 需要一个静态方法,它的参数(见的here )。因此,你需要添加 MethodAttributes.Static innerMethod 的定义。

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

这篇关于LambdaEx pression CompileToMethod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆