private TypeReference ImportTypeSpecification(TypeReference type, ImportGenericContext context) { ElementType etype = type.etype; switch (etype) { case ElementType.Ptr: { PointerType pointerType = (PointerType)type; return(new PointerType(this.ImportType(pointerType.ElementType, context))); } case ElementType.ByRef: { ByReferenceType byReferenceType = (ByReferenceType)type; return(new ByReferenceType(this.ImportType(byReferenceType.ElementType, context))); } case ElementType.ValueType: case ElementType.Class: case ElementType.TypedByRef: case (ElementType)23: case ElementType.I: case ElementType.U: case (ElementType)26: case ElementType.Object: break; case ElementType.Var: { GenericParameter genericParameter = (GenericParameter)type; if (genericParameter.DeclaringType == null) { throw new InvalidOperationException(); } return(context.TypeParameter(genericParameter.DeclaringType.FullName, genericParameter.Position)); } case ElementType.Array: { ArrayType arrayType = (ArrayType)type; ArrayType arrayType2 = new ArrayType(this.ImportType(arrayType.ElementType, context)); if (arrayType.IsVector) { return(arrayType2); } Collection <ArrayDimension> dimensions = arrayType.Dimensions; Collection <ArrayDimension> dimensions2 = arrayType2.Dimensions; dimensions2.Clear(); for (int i = 0; i < dimensions.Count; i++) { ArrayDimension arrayDimension = dimensions[i]; dimensions2.Add(new ArrayDimension(arrayDimension.LowerBound, arrayDimension.UpperBound)); } return(arrayType2); } case ElementType.GenericInst: { GenericInstanceType genericInstanceType = (GenericInstanceType)type; TypeReference type2 = this.ImportType(genericInstanceType.ElementType, context); GenericInstanceType genericInstanceType2 = new GenericInstanceType(type2); Collection <TypeReference> genericArguments = genericInstanceType.GenericArguments; Collection <TypeReference> genericArguments2 = genericInstanceType2.GenericArguments; for (int j = 0; j < genericArguments.Count; j++) { genericArguments2.Add(this.ImportType(genericArguments[j], context)); } return(genericInstanceType2); } case ElementType.FnPtr: { FunctionPointerType functionPointerType = (FunctionPointerType)type; FunctionPointerType functionPointerType2 = new FunctionPointerType { HasThis = functionPointerType.HasThis, ExplicitThis = functionPointerType.ExplicitThis, CallingConvention = functionPointerType.CallingConvention, ReturnType = this.ImportType(functionPointerType.ReturnType, context) }; if (!functionPointerType.HasParameters) { return(functionPointerType2); } for (int k = 0; k < functionPointerType.Parameters.Count; k++) { functionPointerType2.Parameters.Add(new ParameterDefinition(this.ImportType(functionPointerType.Parameters[k].ParameterType, context))); } return(functionPointerType2); } case ElementType.SzArray: { ArrayType arrayType3 = (ArrayType)type; return(new ArrayType(this.ImportType(arrayType3.ElementType, context))); } case ElementType.MVar: { GenericParameter genericParameter2 = (GenericParameter)type; if (genericParameter2.DeclaringMethod == null) { throw new InvalidOperationException(); } return(context.MethodParameter(genericParameter2.DeclaringMethod.Name, genericParameter2.Position)); } case ElementType.CModReqD: { RequiredModifierType requiredModifierType = (RequiredModifierType)type; return(new RequiredModifierType(this.ImportType(requiredModifierType.ModifierType, context), this.ImportType(requiredModifierType.ElementType, context))); } case ElementType.CModOpt: { OptionalModifierType optionalModifierType = (OptionalModifierType)type; return(new OptionalModifierType(this.ImportType(optionalModifierType.ModifierType, context), this.ImportType(optionalModifierType.ElementType, context))); } default: if (etype == ElementType.Sentinel) { SentinelType sentinelType = (SentinelType)type; return(new SentinelType(this.ImportType(sentinelType.ElementType, context))); } if (etype == ElementType.Pinned) { PinnedType pinnedType = (PinnedType)type; return(new PinnedType(this.ImportType(pinnedType.ElementType, context))); } break; } throw new NotSupportedException(type.etype.ToString()); }
public void WriteTypeSignature(TypeReference type) { if (type == null) { throw new ArgumentNullException(); } ElementType etype = type.etype; ElementType elementType = etype; if (elementType <= ElementType.GenericInst) { if (elementType == ElementType.None) { this.WriteElementType(type.IsValueType ? ElementType.ValueType : ElementType.Class); base.WriteCompressedUInt32(this.MakeTypeDefOrRefCodedRID(type)); return; } switch (elementType) { case ElementType.Ptr: case ElementType.ByRef: goto IL_E3; case ElementType.ValueType: case ElementType.Class: goto IL_17D; case ElementType.Var: break; case ElementType.Array: { ArrayType arrayType = (ArrayType)type; if (!arrayType.IsVector) { this.WriteArrayTypeSignature(arrayType); return; } this.WriteElementType(ElementType.SzArray); this.WriteTypeSignature(arrayType.ElementType); return; } case ElementType.GenericInst: { GenericInstanceType genericInstanceType = (GenericInstanceType)type; this.WriteElementType(ElementType.GenericInst); this.WriteElementType(genericInstanceType.IsValueType ? ElementType.ValueType : ElementType.Class); base.WriteCompressedUInt32(this.MakeTypeDefOrRefCodedRID(genericInstanceType.ElementType)); this.WriteGenericInstanceSignature(genericInstanceType); return; } default: goto IL_17D; } } else { switch (elementType) { case ElementType.FnPtr: { FunctionPointerType method = (FunctionPointerType)type; this.WriteElementType(ElementType.FnPtr); this.WriteMethodSignature(method); return; } case ElementType.Object: case ElementType.SzArray: goto IL_17D; case ElementType.MVar: break; case ElementType.CModReqD: case ElementType.CModOpt: { IModifierType type2 = (IModifierType)type; this.WriteModifierSignature(etype, type2); return; } default: if (elementType != ElementType.Sentinel && elementType != ElementType.Pinned) { goto IL_17D; } goto IL_E3; } } GenericParameter genericParameter = (GenericParameter)type; this.WriteElementType(etype); int position = genericParameter.Position; if (position == -1) { throw new NotSupportedException(); } base.WriteCompressedUInt32((uint)position); return; IL_E3: TypeSpecification typeSpecification = (TypeSpecification)type; this.WriteElementType(etype); this.WriteTypeSignature(typeSpecification.ElementType); return; IL_17D: if (!this.TryWriteElementType(type)) { throw new NotSupportedException(); } }
private TypeReference ReadTypeSignature(ElementType etype) { switch (etype) { case ElementType.Void: return(this.TypeSystem.Void); case ElementType.Boolean: case ElementType.Char: case ElementType.I1: case ElementType.U1: case ElementType.I2: case ElementType.U2: case ElementType.I4: case ElementType.U4: case ElementType.I8: case ElementType.U8: case ElementType.R4: case ElementType.R8: case ElementType.String: case (ElementType)23: case (ElementType)26: break; case ElementType.Ptr: return(new PointerType(this.ReadTypeSignature())); case ElementType.ByRef: return(new ByReferenceType(this.ReadTypeSignature())); case ElementType.ValueType: { TypeReference typeDefOrRef = this.GetTypeDefOrRef(this.ReadTypeTokenSignature()); typeDefOrRef.IsValueType = true; return(typeDefOrRef); } case ElementType.Class: return(this.GetTypeDefOrRef(this.ReadTypeTokenSignature())); case ElementType.Var: return(this.GetGenericParameter(GenericParameterType.Type, base.ReadCompressedUInt32())); case ElementType.Array: return(this.ReadArrayTypeSignature()); case ElementType.GenericInst: { bool flag = base.ReadByte() == 17; TypeReference typeDefOrRef2 = this.GetTypeDefOrRef(this.ReadTypeTokenSignature()); GenericInstanceType genericInstanceType = new GenericInstanceType(typeDefOrRef2); this.ReadGenericInstanceSignature(typeDefOrRef2, genericInstanceType); if (flag) { genericInstanceType.IsValueType = true; typeDefOrRef2.GetElementType().IsValueType = true; } return(genericInstanceType); } case ElementType.TypedByRef: return(this.TypeSystem.TypedReference); case ElementType.I: return(this.TypeSystem.IntPtr); case ElementType.U: return(this.TypeSystem.UIntPtr); case ElementType.FnPtr: { FunctionPointerType functionPointerType = new FunctionPointerType(); this.ReadMethodSignature(functionPointerType); return(functionPointerType); } case ElementType.Object: return(this.TypeSystem.Object); case ElementType.SzArray: return(new ArrayType(this.ReadTypeSignature())); case ElementType.MVar: return(this.GetGenericParameter(GenericParameterType.Method, base.ReadCompressedUInt32())); case ElementType.CModReqD: return(new RequiredModifierType(this.GetTypeDefOrRef(this.ReadTypeTokenSignature()), this.ReadTypeSignature())); case ElementType.CModOpt: return(new OptionalModifierType(this.GetTypeDefOrRef(this.ReadTypeTokenSignature()), this.ReadTypeSignature())); default: if (etype == ElementType.Sentinel) { return(new SentinelType(this.ReadTypeSignature())); } if (etype == ElementType.Pinned) { return(new PinnedType(this.ReadTypeSignature())); } break; } return(this.GetPrimitiveType(etype)); }