反思 - 获取里面的lambda EX pression的方法调用列表 [英] Reflection - Get the list of method calls inside a lambda expression

查看:161
本文介绍了反思 - 获取里面的lambda EX pression的方法调用列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方式来获得列表的方式调用内部的lambda EX pression在C#3.5。例如,在下面的code,我想方法LookAtThis(行动)来分析的拉姆达EX pression内容。换句话说,我想LookAtThis回到我创建的MethodInfo的对象。

I am trying to find a way to get the list of method calls inside a lambda expression in C# 3.5. For instance, in the code below, I would like to method LookAtThis(Action a) to analyze the content of the lambda expression. In other words, I want LookAtThis to return me the MethodInfo object of Create.

LookAtThis(() => Create(null, 0));

这可能吗?

谢谢!

推荐答案

这是相当容易的,只要你使用防爆pression&lt;作用&GT; 而不是动作。对于全code,包括如何获得实际值​​暗示,<一个href="http://$c$c.google.com/p/protobuf-net/source/browse/trunk/protobuf-net.Extensions/ServiceModel/Client/ProtoClientExtensions.cs">see这里 - 尤其是 ResolveMethod (以及它是如何使用调用)。这是code我使用protobuf网基于lambda表达式做RPC。

This is fairly easy as long as you use Expression<Action> instead of Action. For full code, including how to get the actual values implied, see here - in particular ResolveMethod (and how it is used by Invoke). This is the code I use in protobuf-net to do RPC based on lambdas.

这篇关于反思 - 获取里面的lambda EX pression的方法调用列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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