Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public ReferenceImporter(MetadataImage image)
     : this(image, new SignatureComparer())
 {
 }
Ejemplo n.º 3
0
 public StandAloneSignature(CallingConventionSignature signature, MetadataImage image)
     : base(new MetadataToken(MetadataTokenType.StandAloneSig))
 {
     _image     = image;
     _signature = new LazyValue <CallingConventionSignature>(signature);
 }
Ejemplo n.º 4
0
 public MemberClonerReferenceImporter(MemberCloner memberCloner, MetadataImage image)
     : base(image)
 {
     _memberCloner = memberCloner;
 }
Ejemplo n.º 5
0
 public ReferenceImporter(MetadataImage image, SignatureComparer signatureComparer)
 {
     TargetImage        = image ?? throw new ArgumentNullException(nameof(image));
     _signatureComparer = signatureComparer;
     _typeSystem        = image.TypeSystem;
 }