我有这个方法
public void Add(Action<Cursor> action)
{
// Decompile `action` to C#
}
在方法内部,我想将内部的匿名方法反编译action 为 C# 代码,或 C# 代码的 AST 表示形式。
我尝试使用Mono.Ceciland ICSharpCode.Decompiler(来自ILSpy存储库),但我找不到反编译匿名方法的方法,因为这两个库都要求您从物理位置加载程序集并通过类型图搜索方法,这看起来非常复杂,尤其是在寻找匿名方法时。
有没有办法使用该方法的 IL Byte 数组,并将其反编译为 C#?
public void Add(Action<Cursor> action)
{
var il = action.Method.GetMethodBody().GetILAsByteArray();
var ast = decompiler.DecompileIL(il); // Does such decompiler exist?
}
天涯尽头无女友
相关分类