Traverse a c# method and anazlye the method body

北战南征 提交于 2019-12-19 16:36:49

问题


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.

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.

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?


回答1:


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



来源:https://stackoverflow.com/questions/3413779/traverse-a-c-sharp-method-and-anazlye-the-method-body

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