相关疑难解决方法(0)

将对象文字提供给ILGenerator

Food obj = ...;
ILGenerator gen = (...).GetILGenerator();
gen.Emit( ?? obj ?? ); // replace this 
gen.Emit(OpCodes.Call, typeof(Person).GetMethod("Eat"));
Run Code Online (Sandbox Code Playgroud)

显然不可能干净地将obj推到评估堆栈上,但我对丑陋的黑客持开放态度,这可能会影响可移植性.ModuleBuilder.DefineInitializedData允许在.sdata中存储System.Byte [].有任何想法吗?

编辑:生成的方法作为新程序集的一部分发出.

c# cil reflection.emit

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

标签 统计

c# ×1

cil ×1

reflection.emit ×1