简体   繁体   English

从Assembly获得MSIL?

[英]Get MSIL from Assembly?

Is it possible to usefully extract MSIL from an Assembly object without loading the type information? 是否可以在不加载类型信息的情况下有效地从Assembly对象提取MSIL?

I have a simple application that takes a string and attempts to dynamically create a method for making very fast calculations, but I want to avoid loading assembly/type information by using the CodeCompileUnit to compile a C# code string, extract the MSIL from the compiled assembly, and emitting the MSIL into a DynamicMethod. 我有一个简单的应用程序,该应用程序需要一个字符串,并尝试动态创建一种用于进行快速计算的方法,但是我想避免通过使用CodeCompileUnit编译C#代码字符串,从已编译的程序集中提取MSIL来加载程序集/类型信息。 ,并将MSIL发送到DynamicMethod中。 If this is possible. 如果可能的话。

看一下Mono.Cecil ,它可以帮助您读取/修改/创建程序集而无需加载它们。

The only way to get MSIL is to call MethodBase.GetMethodBody Method . 获取MSIL的唯一方法是调用MethodBase.GetMethodBody Method But it requires loading of type first. 但是它需要首先加载类型。

Use System.Reflection.Emit directly. 直接使用System.Reflection.Emit For dynamic methods you don't even need a type. 对于动态方法,您甚至不需要类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM