public IMemberSignature ReadMemberRefSignature(uint sig, IGenericContext context) { IMemberSignature signature = null; BlobSignatureReader reader; if (TryGetBlobReader(sig, context, out reader)) { using (reader) { byte flag = reader.ReadByte(); if (flag == 0x6) { FieldSignature fieldsignature = new FieldSignature(); fieldsignature.ReturnType = reader.ReadTypeReference((ElementType)reader.ReadByte()); signature = fieldsignature; } else { MethodSignature methodsignature = new MethodSignature(); if ((flag & 0x20) != 0) { methodsignature.HasThis = true; flag = (byte)(flag & -33); } if ((flag & 0x40) != 0) { methodsignature.ExplicitThis = true; flag = (byte)(flag & -65); } if ((flag & 0x10) != 0) { int genericsig = NETGlobals.ReadCompressedInt32(reader); if (!context.IsDefinition) { AddMissingGenericParameters(context.Method, genericsig - 1); } } methodsignature.CallingConvention = (MethodCallingConvention)flag; uint paramCount = NETGlobals.ReadCompressedUInt32(reader); methodsignature.ReturnType = reader.ReadTypeReference(); ParameterReference[] parameters = new ParameterReference[paramCount]; for (int i = 0; i < paramCount; i++) { parameters[i] = new ParameterReference() { ParameterType = reader.ReadTypeReference((ElementType)reader.ReadByte()) }; } methodsignature.Parameters = parameters; signature = methodsignature; } } } return(signature); }
private ArrayType ReadArrayType(BlobSignatureReader reader) { TypeReference arrayType = ReadTypeReference(reader, (ElementType)reader.ReadByte()); uint rank = NETGlobals.ReadCompressedUInt32(reader); uint[] upperbounds = new uint[NETGlobals.ReadCompressedUInt32(reader)]; for (int i = 0; i < upperbounds.Length; i++) { upperbounds[i] = NETGlobals.ReadCompressedUInt32(reader); } int[] lowerbounds = new int[NETGlobals.ReadCompressedUInt32(reader)]; for (int i = 0; i < lowerbounds.Length; i++) { lowerbounds[i] = NETGlobals.ReadCompressedInt32(reader); } ArrayDimension[] dimensions = new ArrayDimension[rank]; for (int i = 0; i < rank; i++) { int?lower = null; int?upper = null; if (i < lowerbounds.Length) { lower = new int?(lowerbounds[i]); } if (i < upperbounds.Length) { int x = (int)upperbounds[i]; upper = (lower.HasValue ? new int?(lower.GetValueOrDefault() + x) : 0) - 1; } ArrayDimension dimension = new ArrayDimension(lower, upper); dimensions[i] = dimension; } return(new ArrayType(arrayType, (int)rank, dimensions)); }
private TypeReference ReadTypeReference(BlobSignatureReader reader, 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(reader, (ElementType)reader.ReadByte()))); case ElementType.MVar: if (reader.GenericContext == null) { return(new GenericParamReference(NETGlobals.ReadCompressedInt32(reader), new TypeReference(string.Empty, "MVar", null) { elementType = ElementType.MVar, @namespace = "", netheader = this.netheader })); } return(ReadGenericType(reader)); case ElementType.Var: uint token = NETGlobals.ReadCompressedUInt32(reader); if (reader.GenericContext != null) { if (reader.GenericContext.DeclaringType != null && reader.GenericContext.DeclaringType.GenericParameters != null && reader.GenericContext.DeclaringType.GenericParameters.Length > token) { return(reader.GenericContext.DeclaringType.GenericParameters[token]); } else if (reader.GenericContext.GenericParameters != null && reader.GenericContext.GenericParameters.Length > token) { return(reader.GenericContext.GenericParameters[token]); } } return(new GenericParamReference((int)token, new TypeReference(string.Empty, "Var", null) { elementType = ElementType.Var, @namespace = "", netheader = this.netheader })); case ElementType.Array: return(ReadArrayType(reader)); case ElementType.SzArray: return(new ArrayType(ReadTypeReference(reader, (ElementType)reader.ReadByte()))); case ElementType.Class: return((TypeReference)netheader.TablesHeap.TypeDefOrRef.GetMember((int)NETGlobals.ReadCompressedUInt32(reader))); case ElementType.ValueType: TypeReference typeRef = (TypeReference)netheader.TablesHeap.TypeDefOrRef.GetMember((int)NETGlobals.ReadCompressedUInt32(reader)); typeRef.IsValueType = true; return(typeRef); case ElementType.ByRef: return(new ByReferenceType(ReadTypeReference(reader, (ElementType)reader.ReadByte()))); case ElementType.Pinned: return(new PinnedType(ReadTypeReference(reader, (ElementType)reader.ReadByte()))); case ElementType.GenericInst: bool flag = reader.ReadByte() == 0x11; TypeReference reference2 = ReadTypeToken(reader); GenericInstanceType instance = new GenericInstanceType(reference2); this.ReadGenericInstanceSignature(reader, instance); if (flag) { instance.IsValueType = true; } return(instance); } return(new TypeReference(string.Empty, type.ToString(), null) { netheader = this.netheader }); }