Exemple #1
0
        public override AssemblyName[] GetReferencedAssemblies()
        {
            Token token;
            int   num;
            IMetadataAssemblyImport rawImport     = (IMetadataAssemblyImport)this.m_manifestModule.RawImport;
            List <AssemblyName>     assemblyNames = new List <AssemblyName>();
            HCORENUM hCORENUM = new HCORENUM();

            try
            {
                while (true)
                {
                    int num1 = rawImport.EnumAssemblyRefs(ref hCORENUM, out token, 1, out num);
                    Marshal.ThrowExceptionForHR(num1);
                    if (num == 0)
                    {
                        break;
                    }
                    assemblyNames.Add(AssemblyNameHelper.GetAssemblyNameFromRef(token, this.m_manifestModule, rawImport));
                }
            }
            finally
            {
                hCORENUM.Close(rawImport);
            }
            return(assemblyNames.ToArray());
        }
Exemple #2
0
        internal MetadataOnlyAssembly(MetadataOnlyModule[] modules, string manifestFile)
        {
            MetadataOnlyAssembly.VerifyModules(modules);
            this.m_manifestModule = modules[0];
            this.m_name           = AssemblyNameHelper.GetAssemblyName(this.m_manifestModule);
            this.m_manifestFile   = manifestFile;
            MetadataOnlyModule[] metadataOnlyModuleArray = modules;
            for (int num = 0; num < (int)metadataOnlyModuleArray.Length; num++)
            {
                metadataOnlyModuleArray[num].SetContainingAssembly(this);
            }
            List <Module> modules1 = new List <Module>(modules);

            foreach (string fileNamesFromFilesTable in MetadataOnlyAssembly.GetFileNamesFromFilesTable(this.m_manifestModule, false))
            {
                if (modules1.Find((Module i) => i.Name.Equals(fileNamesFromFilesTable, StringComparison.OrdinalIgnoreCase)) != null)
                {
                    continue;
                }
                Module module = this.m_manifestModule.AssemblyResolver.ResolveModule(this, fileNamesFromFilesTable);
                if (module == null)
                {
                    throw new InvalidOperationException(MetadataStringTable.ResolverMustResolveToValidModule);
                }
                if (module.Assembly != this)
                {
                    throw new InvalidOperationException(MetadataStringTable.ResolverMustSetAssemblyProperty);
                }
                modules1.Add(module);
            }
            this.m_modules = modules1.ToArray();
        }
Exemple #3
0
        public static AssemblyName GetAssemblyName(MetadataOnlyModule module)
        {
            PortableExecutableKinds portableExecutableKind;
            ImageFileMachine        imageFileMachine;
            Token assemblyToken = MetadataOnlyAssembly.GetAssemblyToken(module);
            IMetadataAssemblyImport rawImport = (IMetadataAssemblyImport)module.RawImport;

            AssemblyNameHelper.AssemblyNameFromDefitionBuilder assemblyNameFromDefitionBuilder = new AssemblyNameHelper.AssemblyNameFromDefitionBuilder(assemblyToken, module.RawMetadata, rawImport);
            AssemblyName codeBaseFromManifestModule = assemblyNameFromDefitionBuilder.CalculateName();

            codeBaseFromManifestModule.CodeBase = MetadataOnlyAssembly.GetCodeBaseFromManifestModule(module);
            module.GetPEKind(out portableExecutableKind, out imageFileMachine);
            codeBaseFromManifestModule.ProcessorArchitecture = AssemblyNameHelper.CalculateProcArchIndex(portableExecutableKind, imageFileMachine);
            return(codeBaseFromManifestModule);
        }
        internal static IEnumerable <UnresolvedTypeName> GetRawTypeForwardedToAttributes(MetadataOnlyModule manifestModule)
        {
            int                     num;
            uint                    num1;
            int                     num2;
            int                     num3;
            int                     num4;
            CorTypeAttr             corTypeAttr;
            HCORENUM                hCORENUM  = new HCORENUM();
            IMetadataAssemblyImport rawImport = (IMetadataAssemblyImport)manifestModule.RawImport;

            try
            {
                while (true)
                {
                    rawImport.EnumExportedTypes(ref hCORENUM, out num, 1, out num1);
                    if (num1 == 0)
                    {
                        break;
                    }
                    rawImport.GetExportedTypeProps(num, null, 0, out num2, out num3, out num4, out corTypeAttr);
                    Token token = new Token(num3);
                    if (token.TokenType == System.Reflection.Adds.TokenType.AssemblyRef)
                    {
                        StringBuilder stringBuilder = new StringBuilder(num2);
                        rawImport.GetExportedTypeProps(num, stringBuilder, stringBuilder.Capacity, out num2, out num3, out num4, out corTypeAttr);
                        AssemblyName assemblyNameFromRef = AssemblyNameHelper.GetAssemblyNameFromRef(token, manifestModule, rawImport);
                        yield return(new UnresolvedTypeName(stringBuilder.ToString(), assemblyNameFromRef));
                    }
                }
            }
            finally
            {
                hCORENUM.Close(rawImport);
            }
        }