遍历一个C#方法和anazlye方法体 [英] Traverse a c# method and anazlye the method body

查看:245
本文介绍了遍历一个C#方法和anazlye方法体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我最简单的方法来遍历在C#中的MethodInfo?

Whats the easiest way to traverse a methodinfo in c#?

我要遍历方法体,发现现场参考和这样并检索类型。

I want to traverse the method body and find field-references and such and retrieves the types.

在的System.Reflection有:

In System.Reflection there is:

mi.GetMethodBody().GetILAsByteArray()

这是有点低级别的,将需要一些工作之前,我就可以遍历全身。

which is kinda low-level and would require "some" work before I would be able to traverse the body.

我知道塞西尔存在,但与塞西尔内存组件加载有问题。我与岂不等于永远磁盘工作的装配它可以从如编译的内存组件。嘘,我wan't一个干净的解决方案的没有的写作大会临时到磁盘。

I know Cecil exists, but there's a problem in loading an in memory assembly with cecil. The assembly i'm working with is't always "on disk" it can be an in memory assembly compiled from eg. Boo, and I wan't a clean solution without writing the assembly temporary to disk.

还有什么其他的选择有没有在那里为这个?

What other alternatives is there out there for this?

推荐答案

这件事应该有所帮助:的基于反射CIL读者。它的工作通过调用GetILAsByteArray()

This thing should help: Reflection based CIL reader. It operates on byte array obtained by calling GetILAsByteArray()

这篇关于遍历一个C#方法和anazlye方法体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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