protected AbstractTypeEmitter(TypeBuilder typeBuilder)
 {
     typebuilder      = typeBuilder;
     nested           = new NestedClassCollection();
     methods          = new MethodCollection();
     constructors     = new ConstructorCollection();
     properties       = new PropertiesCollection();
     events           = new EventCollection();
     name2GenericType = new Dictionary <String, GenericTypeParameterBuilder>();
 }
Ejemplo n.º 2
0
        public TypeDefinition(string @namespace, string name, TypeAttributes attributes, ITypeDefOrRef baseType = null)
            : base(new MetadataToken(MetadataTokenType.TypeDef))
        {
            Attributes = attributes;
            _namespace = new LazyValue <string>(@namespace);
            _name      = new LazyValue <string>(name);
            _baseType  = new LazyValue <ITypeDefOrRef>(baseType);
            Fields     = new DelegatedMemberCollection <TypeDefinition, FieldDefinition>(this, GetFieldOwner, SetFieldOwner);
            Methods    = new DelegatedMemberCollection <TypeDefinition, MethodDefinition>(this, GetMethodOwner, SetMethodOwner);

            _classLayout   = new LazyValue <ClassLayout>();
            _propertyMap   = new LazyValue <PropertyMap>();
            _eventMap      = new LazyValue <EventMap>();
            _declaringType = new LazyValue <TypeDefinition>();

            CustomAttributes      = new CustomAttributeCollection(this);
            SecurityDeclarations  = new SecurityDeclarationCollection(this);
            NestedClasses         = new NestedClassCollection(this);
            GenericParameters     = new GenericParameterCollection(this);
            Interfaces            = new InterfaceImplementationCollection(this);
            MethodImplementations = new MethodImplementationCollection(this);
        }
Ejemplo n.º 3
0
        internal TypeDefinition(MetadataImage image, MetadataRow <TypeAttributes, uint, uint, uint, uint, uint> row)
            : base(row.MetadataToken)
        {
            Module = image.Assembly.Modules.FirstOrDefault();
            var tableStream  = image.Header.GetStream <TableStream>();
            var stringStream = image.Header.GetStream <StringStream>();

            Attributes = row.Column1;

            _name      = _namespace = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column2));
            _namespace = new LazyValue <string>(() => stringStream.GetStringByOffset(row.Column3));
            _baseType  = new LazyValue <ITypeDefOrRef>(() =>
            {
                var baseTypeToken = tableStream.GetIndexEncoder(CodedIndex.TypeDefOrRef).DecodeIndex(row.Column4);
                if (baseTypeToken.Rid != 0)
                {
                    IMetadataMember baseType;
                    if (image.TryResolveMember(baseTypeToken, out baseType))
                    {
                        return(baseType as ITypeDefOrRef);
                    }
                }
                return(null);
            });

            Fields  = new RangedMemberCollection <TypeDefinition, FieldDefinition>(this, MetadataTokenType.Field, 4, GetFieldOwner, SetFieldOwner);
            Methods = new RangedMemberCollection <TypeDefinition, MethodDefinition>(this, MetadataTokenType.Method, 5, GetMethodOwner, SetMethodOwner);

            _classLayout = new LazyValue <ClassLayout>(() =>
            {
                var table     = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.ClassLayout);
                var layoutRow = table.GetRowByKey(2, row.MetadataToken.Rid);
                return(layoutRow != null ? (ClassLayout)table.GetMemberFromRow(image, layoutRow) : null);
            });

            _propertyMap = new LazyValue <PropertyMap>(() =>
            {
                var table  = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.PropertyMap);
                var mapRow = table.GetRowByKey(0, row.MetadataToken.Rid);
                return(mapRow != null ? (PropertyMap)table.GetMemberFromRow(image, mapRow) : null);
            });

            _eventMap = new LazyValue <EventMap>(() =>
            {
                var table  = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.EventMap);
                var mapRow = table.GetRowByKey(0, row.MetadataToken.Rid);
                return(mapRow != null ? (EventMap)table.GetMemberFromRow(image, mapRow) : null);
            });

            _declaringType = new LazyValue <TypeDefinition>(() =>
            {
                var table          = image.Header.GetStream <TableStream>().GetTable(MetadataTokenType.NestedClass);
                var nestedClassRow = table.GetRowByKey(0, row.MetadataToken.Rid);
                return(nestedClassRow != null
                    ? ((NestedClass)table.GetMemberFromRow(image, nestedClassRow)).EnclosingClass
                    : null);
            });

            CustomAttributes      = new CustomAttributeCollection(this);
            SecurityDeclarations  = new SecurityDeclarationCollection(this);
            NestedClasses         = new NestedClassCollection(this);
            GenericParameters     = new GenericParameterCollection(this);
            Interfaces            = new InterfaceImplementationCollection(this);
            MethodImplementations = new MethodImplementationCollection(this);
        }