在运行时将 IL 代码转换为 C#
是否有任何免费库允许在运行时将 IL 代码转换为 C#?
谢谢, Christian
编辑
这是我所拥有的一个示例:
在我的程序中,在某些时候我有一个字符串列表,这些字符串类似于位于某个程序集中的类的 IL 代码:
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit Probant.Arithmetics
extends [mscorlib]System.Object
{
.method public hidebysig instance int32
Sum(int32 a,
int32 b) cil managed
{
// Code size 11 (0xb)
.maxstack 2
.locals init ([0] int32 result,
[1] int32 CS$1$0000)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: add
IL_0004: stloc.0
IL_0005: ldloc.0
IL_0006: stloc.1
IL_0007: br.s IL_0009
IL_0009: ldloc.1
IL_000a: ret
现在有这个数组字符串(每个字符串一行),我想以某种方式生成相应的 C# 代码。
有谁知道ILSpy是否可以做到这一点?
Is there any free library that allows to transform IL code to C# at runtime?
Thanks,
Christian
EDIT
Here is an example of what I have:
In my program, at some point I have a list of strings which resemble the IL code of a class that lies in some assembly:
// =============== CLASS MEMBERS DECLARATION ===================
.class public auto ansi beforefieldinit Probant.Arithmetics
extends [mscorlib]System.Object
{
.method public hidebysig instance int32
Sum(int32 a,
int32 b) cil managed
{
// Code size 11 (0xb)
.maxstack 2
.locals init ([0] int32 result,
[1] int32 CS$1$0000)
IL_0000: nop
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: add
IL_0004: stloc.0
IL_0005: ldloc.0
IL_0006: stloc.1
IL_0007: br.s IL_0009
IL_0009: ldloc.1
IL_000a: ret
Now having this array of strings (each string a line), I would like to somehow generate corresponding C# code.
Does anyone know whether this is possible with ILSpy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我而言:
As per me:
ILSpy 使用 Mono.Cecil 读取输入程序集,然后使用 Cecils 中间表示形式。
如果您将 IL 作为文本而不是二进制文件,则必须找到可以将文本组装成程序集或至少组装成 Cecils 表示形式的东西。
ILSpy reads the input assemblies using Mono.Cecil and then works with the Cecils intermediate representation.
If you have the IL as a text rather then binary you would have to find something that can assemble the text into assembly or at least into the Cecils representation.