How to detemine (by code) the assembly corflags?
I need to write a CorFlags-like application. If I have a path to assembly file, how to I read its CorFlags?
I specifically need to know if the assembly is An开发者_StackOverflowy-CPU or x86 only
I want to avoid loading the assembly using reflection because I need to scan many files.
Have a look at this link, it describes a similar situation to your query. The accepted answer describes how you can use reflection and Module.GetPEKind. This might help you.
Edit: A bit late, but here's a example:
namespace ConsoleApplication1
{
using System.Reflection;
public class Program
{
public static void Main()
{
Assembly a = Assembly.GetExecutingAssembly();
PortableExecutableKinds peKind;
ImageFileMachine machine;
a.ManifestModule.GetPEKind(out peKind, out machine);
}
}
}
System.Reflection.Assembly has a whole bunch of things to help you in this.
var asmbly = Assembly.ReflectionOnlyLoad("filename");
var PeFlags = asmbly.ManifestModule.GetPEKind();
//PeFlags is effectively CorFlags.
If you don't want to use reflection, you may check out
CCI http://ccimetadata.codeplex.com/Wiki/View.aspx?title=API%20overview or
Mono.Cecil http://www.mono-project.com/Cecil
精彩评论