Inheritance: TypeSpecification, IGenericInstance, IGenericContext
Ejemplo n.º 1
0
        private void ReadGenericInstanceSignature(BinaryReader reader, IGenericParametersProvider provider, GenericInstanceType type)
        {
            uint number = ReadCompressedUInt32(reader);

            //provider.GenericParameters = new GenericParameter[number];
            type.GenericArguments = new TypeReference[number];

            for (int i = 0; i < number; i++)
                type.GenericArguments[i] = ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider);
        }
Ejemplo n.º 2
0
        public TypeReference ReadTypeReference(ElementType type)
        {
            switch (type)
            {
                case ElementType.Void:
                    return _netHeader.TypeSystem.Void;
                case ElementType.I:
                    return _netHeader.TypeSystem.IntPtr;
                case ElementType.I1:
                    return _netHeader.TypeSystem.Int8;
                case ElementType.I2:
                    return _netHeader.TypeSystem.Int16;
                case ElementType.I4:
                    return _netHeader.TypeSystem.Int32;
                case ElementType.I8:
                    return _netHeader.TypeSystem.Int64;
                case ElementType.U:
                    return _netHeader.TypeSystem.UIntPtr;
                case ElementType.U1:
                    return _netHeader.TypeSystem.UInt8;
                case ElementType.U2:
                    return _netHeader.TypeSystem.UInt16;
                case ElementType.U4:
                    return _netHeader.TypeSystem.UInt32;
                case ElementType.U8:
                    return _netHeader.TypeSystem.UInt64;
                case ElementType.Object:
                    return _netHeader.TypeSystem.Object;
                case ElementType.R4:
                    return _netHeader.TypeSystem.Single;
                case ElementType.R8:
                    return _netHeader.TypeSystem.Double;
                case ElementType.String:
                    return _netHeader.TypeSystem.String;
                case ElementType.Char:
                    return _netHeader.TypeSystem.Char;
                case ElementType.Type:
                    return _netHeader.TypeSystem.Type;
                case ElementType.Boolean:
                    return _netHeader.TypeSystem.Boolean;
                case ElementType.Ptr:
                    return new PointerType(ReadTypeReference((ElementType)this.ReadByte()));
                case ElementType.MVar:
                    return GetGenericParameter(GenericParamType.Method, (int)NETGlobals.ReadCompressedUInt32(this));
                case ElementType.Var:
                    return GetGenericParameter(GenericParamType.Type, (int)NETGlobals.ReadCompressedUInt32(this));
                case ElementType.Array:
                    return ReadArrayType();
                case ElementType.SzArray:
                    return new ArrayType(ReadTypeReference((ElementType)this.ReadByte()));
                case ElementType.Class:
                    TypeReference typeRef;
                    if (_netHeader.TablesHeap.TypeDefOrRef.TryGetMember((int)NETGlobals.ReadCompressedUInt32(this), out typeRef))
                    {
                        return typeRef;
                    }
                    break;
                case ElementType.ValueType:
                    if (_netHeader.TablesHeap.TypeDefOrRef.TryGetMember((int)NETGlobals.ReadCompressedUInt32(this), out typeRef))
                    {
                        typeRef.IsValueType = true;
                        return typeRef;
                    }
                    break;

                case ElementType.ByRef:
                    return new ByReferenceType(ReadTypeReference( (ElementType)this.ReadByte()));
                case ElementType.Pinned:
                    return new PinnedType(ReadTypeReference((ElementType)this.ReadByte()));
                case ElementType.GenericInst:
                    bool isValueType = this.ReadByte() == 0x11;
                    TypeReference reference2 = ReadTypeToken();
                    GenericInstanceType instance = new GenericInstanceType(reference2);
                    instance._genericArguments = ReadGenericArguments();
                    instance.IsValueType = isValueType;

                    return instance;

                case ElementType.CModOpt:
                    return new CustomModifierType(ReadTypeToken(), ReadTypeReference(), false);
                case ElementType.CModReqD:
                    return new CustomModifierType(ReadTypeToken(), ReadTypeReference(), true);
            }
            return new TypeReference(string.Empty, type.ToString(), null) { _netheader = this._netHeader };
        }
Ejemplo n.º 3
0
        internal TypeReference ReadTypeReference(BinaryReader reader, ElementType type, IGenericParametersProvider provider)
        {
            switch (type)
            {
                case ElementType.Void:
                    return netheader.TypeSystem.Void;
                case ElementType.I:
                    return netheader.TypeSystem.IntPtr;
                case ElementType.I1:
                    return netheader.TypeSystem.Int8;
                case ElementType.I2:
                    return netheader.TypeSystem.Int16;
                case ElementType.I4:
                    return netheader.TypeSystem.Int32;
                case ElementType.I8:
                    return netheader.TypeSystem.Int64;
                case ElementType.U:
                    return netheader.TypeSystem.UIntPtr;
                case ElementType.U1:
                    return netheader.TypeSystem.UInt8;
                case ElementType.U2:
                    return netheader.TypeSystem.UInt16;
                case ElementType.U4:
                    return netheader.TypeSystem.UInt32;
                case ElementType.U8:
                    return netheader.TypeSystem.UInt64;
                case ElementType.Object:
                    return netheader.TypeSystem.Object;
                case ElementType.R4:
                    return netheader.TypeSystem.Single;
                case ElementType.R8:
                    return netheader.TypeSystem.Double;
                case ElementType.String:
                    return netheader.TypeSystem.String;
                case ElementType.Char:
                    return netheader.TypeSystem.Char;
                case ElementType.Type:
                    return netheader.TypeSystem.Type;
                case ElementType.Boolean:
                    return netheader.TypeSystem.Boolean;
                case ElementType.Ptr:
                    return new PointerType(ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider));
                case ElementType.MVar:
                    uint token = ReadCompressedUInt32(reader);
                    if (provider != null && provider.GenericParameters != null && provider.GenericParameters.Length > token)
                        return provider.GenericParameters[token];
                    else
                        return new GenericParamReference((int)token, new TypeReference() { name = "MVar", elementType = ElementType.MVar, @namespace = "", netheader = this.netheader });

                case ElementType.Var:
                    token =ReadCompressedUInt32(reader);
                    if (provider != null && provider is MemberReference)
                    {
                        var member = provider as MemberReference;
                        if (member.DeclaringType is IGenericParametersProvider)
                        {
                            var genericprovider = (IGenericParametersProvider)member.DeclaringType;
                            if (genericprovider.GenericParameters != null)
                                return genericprovider.GenericParameters[token];
                        }
                    }
                    return new GenericParamReference((int)token, new TypeReference() { name = "Var", elementType = ElementType.Var, @namespace = "", netheader = this.netheader });

                    break;
                case ElementType.Array:

                    return ReadArrayType(reader);

                case ElementType.SzArray:
                    return new ArrayType(ReadTypeReference(reader,(ElementType)reader.ReadByte(), provider));
                case ElementType.Class:
                    return (TypeReference)netheader.TablesHeap.tablereader.TypeDefOrRef.GetMember((int)ReadCompressedUInt32(reader));
                case ElementType.ValueType:
                    TypeReference typeRef = (TypeReference)netheader.TablesHeap.tablereader.TypeDefOrRef.GetMember((int)ReadCompressedUInt32(reader));
                    typeRef.IsValueType = true;
                    return typeRef;
                case ElementType.ByRef:
                    return new ByReferenceType(ReadTypeReference(reader, (ElementType)reader.ReadByte(), provider));
                case ElementType.Pinned:
                    return new PinnedType(ReadTypeReference(reader, (ElementType)reader.ReadByte(), provider));
                case ElementType.GenericInst:
                    bool flag = reader.ReadByte() == 0x11;
                    TypeReference reference2 = ReadTypeToken(reader);
                    GenericInstanceType instance = new GenericInstanceType(reference2);
                     this.ReadGenericInstanceSignature(reader,reference2, instance);
                    if (flag)
                    {
                        instance.IsValueType = true;

                    }
                    return instance;
            }
            return new TypeReference() { name = type.ToString(), @namespace = "" , netheader = this.netheader};
        }