相关疑难解决方法(0)

通过动态方法解析IL中发现的令牌

感谢Hans Passant在这里回答我的问题: 如何从DynamicMethod获取IL bytearray?

我能够起床和跑步.我现在正在尝试解决在IL发出的元数据令牌,以查看正在调用哪些方法,或者什么不是.我能够解决方法体中的下一个标记是一个调用.我正在使用来自Mono.ReflectionMethodBodyReader的一些代码.

static byte[] GetILByteArray(Delegate @delegate){
   // does stuff mentioned in other thread
}
...
Expression<Action> foo = () => Console.WriteLine(0);
var compiled = foo.Compile();
var bytes = GetILByteArray(compiled);
int index =Array.FindIndex(bytes,b=>GetOpCode(b).OperandType == OperandType.InlineMethod);
var token = BitConverter.ToInt32(bytes,index+1);
compiled.Method.Module.ResolveMember(token);
Run Code Online (Sandbox Code Playgroud)

引发异常,说明该域中的令牌是不可解析的.这里有人有诀窍吗?我应该尝试传递代理通用参数还是完全没用?

我现在正在考虑为表达式树的代表编写一个反编译器的想法,我真的希望能够使用我自己编译为测试用例的表达式树,因为我总是可以回到原始版本并进行比较.

c# dynamicmethod

5
推荐指数
1
解决办法
1215
查看次数

标签 统计

c# ×1

dynamicmethod ×1