コード例 #1
0
        internal int ImportType(Type type)
        {
            int token;

            if (!typeTokens.TryGetValue(type, out token))
            {
                if (type.HasElementType || (type.IsGenericType && !type.IsGenericTypeDefinition))
                {
                    ByteBuffer spec = new ByteBuffer(5);
                    Signature.WriteTypeSpec(this, spec, type);
                    token = 0x1B000000 | this.TypeSpec.AddRecord(this.Blobs.Add(spec));
                }
                else
                {
                    TypeRefTable.Record rec = new TypeRefTable.Record();
                    if (type.IsNested)
                    {
                        rec.ResolutionScope = GetTypeToken(type.DeclaringType).Token;
                        rec.TypeName        = this.Strings.Add(TypeNameParser.Unescape(type.Name));
                        rec.TypeNameSpace   = 0;
                    }
                    else
                    {
                        rec.ResolutionScope = ImportAssemblyRef(type.Assembly);
                        rec.TypeName        = this.Strings.Add(TypeNameParser.Unescape(type.Name));
                        string ns = type.Namespace;
                        rec.TypeNameSpace = ns == null ? 0 : this.Strings.Add(TypeNameParser.Unescape(ns));
                    }
                    token = 0x01000000 | this.TypeRef.AddRecord(rec);
                }
                typeTokens.Add(type, token);
            }
            return(token);
        }
コード例 #2
0
        internal void ExportTypes(int fileToken, ModuleBuilder manifestModule)
        {
            Dictionary <Type, int> declaringTypes = new Dictionary <Type, int>();

            foreach (TypeBuilder type in types)
            {
                if (type != moduleType && IsVisible(type))
                {
                    ExportedTypeTable.Record rec = new ExportedTypeTable.Record();
                    rec.Flags     = (int)type.Attributes;
                    rec.TypeDefId = type.MetadataToken & 0xFFFFFF;
                    rec.TypeName  = manifestModule.Strings.Add(TypeNameParser.Unescape(type.Name));
                    string ns = type.Namespace;
                    rec.TypeNamespace = ns == null ? 0 : manifestModule.Strings.Add(TypeNameParser.Unescape(ns));
                    if (type.IsNested)
                    {
                        rec.Implementation = declaringTypes[type.DeclaringType];
                    }
                    else
                    {
                        rec.Implementation = fileToken;
                    }
                    int exportTypeToken = 0x27000000 | manifestModule.ExportedType.AddRecord(rec);
                    declaringTypes.Add(type, exportTypeToken);
                }
            }
        }
コード例 #3
0
 private int ExportType(Type type)
 {
     ExportedTypeTable.Record rec = new ExportedTypeTable.Record();
     rec.TypeDefId = type.MetadataToken;
     rec.TypeName  = this.Strings.Add(TypeNameParser.Unescape(type.Name));
     if (type.IsNested)
     {
         rec.Flags          = 0;
         rec.TypeNamespace  = 0;
         rec.Implementation = ExportType(type.DeclaringType);
     }
     else
     {
         rec.Flags = 0x00200000;                 // CorTypeAttr.tdForwarder
         string ns = type.Namespace;
         rec.TypeNamespace  = ns == null ? 0 : this.Strings.Add(TypeNameParser.Unescape(ns));
         rec.Implementation = ImportAssemblyRef(type.Assembly);
     }
     return(0x27000000 | this.ExportedType.FindOrAddRecord(rec));
 }