How do I expand (by code) an assembly of flags?

I need to write an application like CorFlags. If I have the path to the assembly file, how can I read it from CorFlags?

I especially need to know if the assembly is Any-CPU or x86 only

I want to avoid loading an assembly using reflection because I have to scan a lot of files.

+2


source to share


3 answers


If you don't want to use reflection, you can check

CCI http://ccimetadata.codeplex.com/Wiki/View.aspx?title=API%20overview or



Mono.Cecil http://www.mono-project.com/Cecil

+3


source


Check out this link, it describes a similar situation with your request. The accepted answer describes how you can use reflection and Module.GetPEKind . This might help you.

Edit: a little late, but here's an 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);
        }
    }
}

      

+10


source


System.Reflection.Assembly has a whole bunch of things to help you with this.

var asmbly = Assembly.ReflectionOnlyLoad("filename");
var PeFlags = asmbly.ManifestModule.GetPEKind();
//PeFlags is effectively CorFlags.

      

+4


source







All Articles