當前位置: 首頁>>代碼示例>>C#>>正文


C# Assembly.GetFiles方法代碼示例

本文整理匯總了C#中Assembly.GetFiles方法的典型用法代碼示例。如果您正苦於以下問題:C# Assembly.GetFiles方法的具體用法?C# Assembly.GetFiles怎麽用?C# Assembly.GetFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Assembly的用法示例。


在下文中一共展示了Assembly.GetFiles方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: PrintAssembly

    void PrintAssembly(Assembly asm)
    {
        // assembly name
        AssemblyName[] asms = asm.GetReferencedAssemblies();

        // Pre-Load the referenced assemblies first
        // user can specify customerized reference through /asmpath option

        foreach (AssemblyName a in asms)
        {
            if (TryLoadAssembly(a) == null)
            {
                throw new ApplicationException("Fail to Find " + a.Name);
            }
        }
        Console.WriteLine("Loaded Assemblies");
        Assembly[] asmss = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies();
        foreach (Assembly assembly in asmss)
            Console.WriteLine(assembly);

        Array.Sort(asms, sc);
        foreach (AssemblyName a in asms)
            PrintAssemblyName(null, a, true);
        PrintAssemblyName(asm, asm.GetName(), false);
        // module
        Module amod = asm.ManifestModule;
        Module[] mods = asm.GetModules(true);
        Array.Sort(mods, sc);
        foreach (Module mod in mods)
        {
            if (!mod.Name.Equals(amod.Name))
                sw.WriteLine(".module manifest " + mod.Name);
            else if (!mod.IsResource())
                sw.WriteLine(".module " + mod.Name);
            else sw.WriteLine(".resource " + mod.Name);
            PrintCustomAttributes(CustomAttributeData.GetCustomAttributes(mod));

        }
        // file
        FileStream[] files = asm.GetFiles();
        Array.Sort(files, sc);
        foreach (FileStream file in files)
            sw.WriteLine(".file " + Path.GetFileName(file.Name)); // TODO seems the file api has provided less than CLI such as hashcode
        // .subsystem (Console or UI)We cannot get it from reflection
        // .corflags ( 64, 32 or IL platforms)
        PortableExecutableKinds PEKind = (PortableExecutableKinds)0;
        ImageFileMachine Machine = (ImageFileMachine)0;
        asm.ManifestModule.GetPEKind(out PEKind, out Machine);
        sw.WriteLine(".pekind " + PEKind);
        sw.WriteLine(".imageMachine " + Machine);
        // .class
        Type[] ts = amod.GetTypes();
        Array.Sort(ts, sc);
        foreach (Type t in ts)
            PrintType(t, false);
        // .field and .method (only the manifest module ... )
        FieldInfo[] fis = amod.GetFields(bf);
        Array.Sort(fis, sc);
        foreach (FieldInfo fi in fis) // global fields
            PrintField(fi);
        MethodInfo[] mis = amod.GetMethods(bf);
        Array.Sort(mis, sc);
        foreach (MethodInfo mi in mis) // global methods
            PrintMethod(mi);

        Console.WriteLine("Loaded Assemblies");
        asmss = AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies();
        foreach (Assembly assembly in asmss)
            Console.WriteLine(assembly);
    }
開發者ID:dbremner,項目名稱:clrinterop,代碼行數:70,代碼來源:AssemPrinter.cs


注:本文中的Assembly.GetFiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。