Inheritance: MemberReference, IGenericParametersProvider
示例#1
0
 public TypeDefinition(string @namespace, string name, TypeAttributes attributes, TypeReference baseType, uint fieldList, uint methodList)
     : base(new MetaDataRow((uint)attributes, 0U, 0U, 0U, fieldList, methodList))
 {
     this._namespace = @namespace;
     this._name = name;
     this._baseType = baseType;
 }
 public TypeSpecification(TypeReference typeRef)
 {
     originaltype = typeRef;
     netheader = typeRef.netheader;
     IsArray = typeRef.IsArray;
     IsPointer = typeRef.IsPointer;
     IsByReference = typeRef.IsByReference;
     IsDefinition = typeRef.IsDefinition;
     IsGenericInstance = typeRef.IsGenericInstance;
     IsPinned = typeRef.IsPinned;
     IsValueType = typeRef.IsValueType;
 }
示例#3
0
 public ArrayType(TypeReference typeRef, int rank, ArrayDimension[] dimensions)
     : base(typeRef)
 {
     //    System.Diagnostics.Debugger.Break();
     this.name = typeRef.name;
     if (rank == 0)
         this.name += "[]";
     else
         for (int i = 0; i < rank; i++)
             this.name = this.name + dimensions[i].ToString();
     Rank = rank;
     Dimensions = dimensions;
 }
示例#4
0
        public virtual TypeDefinition ResolveType(TypeReference typeRef)
        {
            Win32Assembly targetAssembly = null;
            typeRef = typeRef.GetElementType();

            if (typeRef.IsNested)
            {
                var declaringType = ResolveType(typeRef.DeclaringType);
                foreach (var nestedClass in declaringType.NestedClasses)
                {
                    if (nestedClass.Class != null && TypeRefsAreEqual(nestedClass.Class, typeRef))
                    {
                        return nestedClass.Class;
                    }
                }
            }
            else
            {
                if (typeRef.ResolutionScope is AssemblyDefinition)
                {
                    targetAssembly = typeRef.ResolutionScope.NETHeader.ParentAssembly;
                }
                else if (typeRef.ResolutionScope is AssemblyReference)
                {
                    targetAssembly = AssemblyResolver.Resolve(typeRef.ResolutionScope as AssemblyReference);
                }

                if (targetAssembly == null)
                {
                    return null;
                }

                var typesTable = targetAssembly.NETHeader.TablesHeap.GetTable(MetaDataTableType.TypeDef);

                foreach (TypeDefinition member in typesTable.Members)
                {
                    if (TypeRefsAreEqual(member, typeRef))
                    {
                        return member;
                    }
                }
            }
            return null;
        }
示例#5
0
 public override void ClearCache()
 {
     _owner = null;
     _constraint = null;
 }
示例#6
0
 public override void LoadCache()
 {
     _owner = Owner;
     _constraint = Constraint;
 }
示例#7
0
 private void UpdateTypeRef(Workspace workspace, TypeReference typeRef)
 {
     typeRef.MetaDataRow.Parts[0] = GetMemberIndex(workspace, typeRef._resolutionScope as MetaDataMember);
     typeRef.MetaDataRow.Parts[1] = GetStringIndex(workspace, typeRef.Namespace);
     typeRef.MetaDataRow.Parts[2] = GetStringIndex(workspace, typeRef.Name);
 }
示例#8
0
 public GenericParamConstraint(GenericParameter owner, TypeReference constraint)
     : base(new MetaDataRow(owner.TableIndex, 0U))
 {
     this._owner = owner;
     this._constraint = constraint;
 }
示例#9
0
        public object ReadCustomAttributeArgumentElement(TypeReference paramType)
        {
            if (paramType._elementType == ElementType.None)
            {
                // TODO: convert string to type ref:
                if (paramType.FullName == "System.Type")
                    return ReadUtf8String();

                var resolvedTypeDef = paramType.Resolve();
                if (resolvedTypeDef != null)
                {
                    var enumType = resolvedTypeDef.GetEnumType();
                    if (enumType != null)
                        return ReadCustomAttributeArgumentElement(enumType);
                }
                return null;
            }
            else
            {
                if (paramType._elementType == ElementType.String)
                    return ReadUtf8String();

                return ReadPrimitiveValue(paramType._elementType);
            }
        }
示例#10
0
        protected virtual bool TypeRefsAreEqual(TypeReference reference1, TypeReference reference2)
        {
            if (reference1 == null || reference2 == null)
                return false;
            if ((reference1.Name != reference2.Name) || (reference1.Namespace != reference2.Namespace))
                return false;
            if (reference1.HasGenericParameters != reference2.HasGenericParameters)
                return false;
            if (reference1.HasGenericParameters && reference2.HasGenericParameters)
            {
                if (reference1.GenericParameters.Length != reference2.GenericParameters.Length)
                    return false;

                //for (int i = 0; i < reference1.GenericParameters.Length; i++)
                //{
                //    if (!GenericParamsAreEqual(reference1.GenericParameters[i], reference2.GenericParameters[i]))
                //        return false;
                //}
            }
            return true;
        }
示例#11
0
 public ArrayType(TypeReference typeRef)
     : this(typeRef, 0,  null)
 {
 }
示例#12
0
        public object ReadCustomAttributeArgumentValue(TypeReference paramType)
        {
            if (!paramType.IsArray || !(paramType as ArrayType).IsVector)
                return ReadCustomAttributeArgumentElement(paramType);

            // throw new NotImplementedException("Array constructor values are not supported yet.");

            ushort elementcount = this.ReadUInt16();
            object[] elements = new object[elementcount];
            for (int i = 0; i < elementcount; i++)
                elements[i] = ReadCustomAttributeArgumentElement((paramType as ArrayType).OriginalType);

            return elements;
        }
示例#13
0
 public override void LoadCache()
 {
     _addmethod = AddMethod;
     _removemethod = RemoveMethod;
     _name = Name;
     _eventType = EventType;
 }
示例#14
0
 public EventDefinition(string name, EventAttributes attributes, TypeReference eventType)
     : base(new MetaDataRow((ushort)attributes, 0U, 0U))
 {
     this._name = name;
     this._eventType = eventType;
 }
示例#15
0
 public override void ClearCache()
 {
     _addmethod = null;
     _removemethod = null;
     _name = null;
     _eventType = null;
 }
示例#16
0
 public GenericInstanceType(TypeReference typeRef)
     : base(typeRef)
 {
 }
示例#17
0
 public PointerType(TypeReference typeRef)
     : base(typeRef)
 {
     this.name = typeRef.Name + "*";
 }
示例#18
0
 public ByReferenceType(TypeReference typeRef)
     : base(typeRef)
 {
 }
示例#19
0
 public ArrayType(TypeReference typeRef, int rank, ArrayDimension[] dimensions)
     : base(typeRef)
 {
     Rank = rank;
     Dimensions = dimensions;
 }
示例#20
0
 public override void ClearCache()
 {
     signature = null;
     declaringType = null;
     name = null;
 }
 public override void ClearCache()
 {
     @class = null;
     @interface = null;
 }
示例#22
0
        public TypeReference[] ReadGenericArguments()
        {
            uint number = NETGlobals.ReadCompressedUInt32(this);

            var genericArguments = new TypeReference[number];

            for (int i = 0; i < number; i++)
                genericArguments[i] = ReadTypeReference();

            return genericArguments;
        }
示例#23
0
 public FieldReference(string name, TypeReference declaringType, uint signature)
     : base(new MetaDataRow(0U, 0U, signature))
 {
     this._name = name;
     this._declaringType = declaringType;
 }
示例#24
0
 public bool IsBasedOn(TypeReference typeRef)
 {
     return BaseType != null && BaseType.FullName == typeRef.FullName;
 }
示例#25
0
 public override void LoadCache()
 {
     _pinvokeimpl = PInvokeImplementation;
     _customAttributes = CustomAttributes;
     _declaringType = DeclaringType;
 }
示例#26
0
        private object ReadArgumentValue(BinaryReader reader, TypeReference paramType)
        {
            if (!paramType.IsArray || !(paramType as ArrayType).IsVector)
                return ReadElement(reader,paramType);

               // throw new NotImplementedException("Array constructor values are not supported yet.");

            ushort elementcount = reader.ReadUInt16();
            object[] elements = new object[elementcount];
            for (int i = 0; i < elementcount; i++)
                elements[i] = ReadElement(reader,(paramType as ArrayType).OriginalType);

            return elements;
        }
 internal GenericParamReference(int index, TypeReference baseType)
     : base(baseType)
 {
     Index = index;
     IsMethodVar = baseType.elementType == ElementType.MVar;
 }
示例#28
0
        private object ReadElement(BinaryReader reader, TypeReference paramType)
        {
            switch (paramType.elementType)
            {
                case ElementType.I1:
                    return reader.ReadSByte();
                case ElementType.I2:
                    return reader.ReadInt16();
                case ElementType.I4:
                    return reader.ReadInt32();
                case ElementType.I8:
                    return reader.ReadInt64();
                case ElementType.U1:
                    return reader.ReadByte();
                case ElementType.U2:
                    return reader.ReadInt16();
                case ElementType.U4:
                    return reader.ReadInt32();
                case ElementType.U8:
                    return reader.ReadInt64();
                case ElementType.R4:
                    return reader.ReadSingle();
                case ElementType.R8:
                    return reader.ReadDouble();
                case ElementType.Type:
                case ElementType.String:
                    uint size = ReadCompressedUInt32(reader);
                    if (size == 0xFF)
                        return string.Empty;
                    byte[] rawdata = reader.ReadBytes((int)size);
                    return Encoding.UTF8.GetString(rawdata);
                case ElementType.Char:
                    return reader.ReadChar();
                    throw new NotSupportedException();
                case ElementType.Boolean:
                    return reader.ReadByte() == 1;

            }
            return null;
        }
示例#29
0
 public PinnedType(TypeReference typeRef)
     : base(typeRef)
 {
 }
示例#30
0
 public CustomModifierType(TypeReference modifierType, TypeReference baseType, bool isRequired)
     : base(baseType)
 {
     ModifierType = modifierType;
     IsRequired = isRequired;
 }
示例#31
0
 public EventDefinition(string name, EventAttributes attributes, TypeReference eventType)
     : base(new MetaDataRow((ushort)attributes, 0U, 0U))
 {
     this.name      = name;
     this.eventType = eventType;
 }