Example #1
0
        internal MetadataModule(ICompilation compilation, Metadata.PEFile peFile, TypeSystemOptions options)
        {
            this.Compilation  = compilation;
            this.PEFile       = peFile;
            this.metadata     = peFile.Metadata;
            this.options      = options;
            this.TypeProvider = new TypeProvider(this);

            // assembly metadata
            if (metadata.IsAssembly)
            {
                var asmdef = metadata.GetAssemblyDefinition();
                this.AssemblyName     = metadata.GetString(asmdef.Name);
                this.FullAssemblyName = metadata.GetFullAssemblyName();
            }
            else
            {
                var moddef = metadata.GetModuleDefinition();
                this.AssemblyName     = metadata.GetString(moddef.Name);
                this.FullAssemblyName = this.AssemblyName;
            }
            this.rootNamespace = new MetadataNamespace(this, null, string.Empty, metadata.GetNamespaceDefinitionRoot());

            if (!options.HasFlag(TypeSystemOptions.Uncached))
            {
                // create arrays for resolved entities, indexed by row index
                this.typeDefs     = new MetadataTypeDefinition[metadata.TypeDefinitions.Count + 1];
                this.fieldDefs    = new MetadataField[metadata.FieldDefinitions.Count + 1];
                this.methodDefs   = new MetadataMethod[metadata.MethodDefinitions.Count + 1];
                this.propertyDefs = new MetadataProperty[metadata.PropertyDefinitions.Count + 1];
                this.eventDefs    = new MetadataEvent[metadata.EventDefinitions.Count + 1];
            }
        }
Example #2
0
        internal MetadataModule(ICompilation compilation, Metadata.PEFile peFile, TypeSystemOptions options)
        {
            this.Compilation  = compilation;
            this.PEFile       = peFile;
            this.metadata     = peFile.Metadata;
            this.options      = options;
            this.TypeProvider = new TypeProvider(this);

            // assembly metadata
            if (metadata.IsAssembly)
            {
                var asmdef = metadata.GetAssemblyDefinition();
                try
                {
                    this.AssemblyName     = metadata.GetString(asmdef.Name);
                    this.AssemblyVersion  = asmdef.Version;
                    this.FullAssemblyName = metadata.GetFullAssemblyName();
                }
                catch (BadImageFormatException)
                {
                    this.AssemblyName     = "<ERR: invalid assembly name>";
                    this.FullAssemblyName = "<ERR: invalid assembly name>";
                }
            }
            else
            {
                try
                {
                    var moddef = metadata.GetModuleDefinition();
                    this.AssemblyName = metadata.GetString(moddef.Name);
                }
                catch (BadImageFormatException)
                {
                    this.AssemblyName = "<ERR: invalid assembly name>";
                }
                this.FullAssemblyName = this.AssemblyName;
            }
            var customAttrs = metadata.GetModuleDefinition().GetCustomAttributes();

            this.NullableContext        = customAttrs.GetNullableContext(metadata) ?? Nullability.Oblivious;
            this.minAccessibilityForNRT = FindMinimumAccessibilityForNRT(metadata, customAttrs);
            this.rootNamespace          = new MetadataNamespace(this, null, string.Empty, metadata.GetNamespaceDefinitionRoot());

            if (!options.HasFlag(TypeSystemOptions.Uncached))
            {
                // create arrays for resolved entities, indexed by row index
                this.typeDefs             = new MetadataTypeDefinition[metadata.TypeDefinitions.Count + 1];
                this.fieldDefs            = new MetadataField[metadata.FieldDefinitions.Count + 1];
                this.methodDefs           = new MetadataMethod[metadata.MethodDefinitions.Count + 1];
                this.propertyDefs         = new MetadataProperty[metadata.PropertyDefinitions.Count + 1];
                this.eventDefs            = new MetadataEvent[metadata.EventDefinitions.Count + 1];
                this.referencedAssemblies = new IModule[metadata.AssemblyReferences.Count + 1];
            }
        }