internal FieldOrPropertyNamedArgumentExpression( IName name, ITypeReference containingType, bool isField, ITypeReference fieldOrPropTypeReference, ExpressionBase expressionValue ) { this.Name = name; this.ContainingType = containingType; if (isField) this.Flags |= FieldOrPropertyNamedArgumentExpression.IsFieldFlag; this.fieldOrPropTypeReference = fieldOrPropTypeReference; this.ExpressionValue = expressionValue; }
protected ExpressionBase/*?*/ ReadSerializedValue(ITypeReference type) { switch (type.TypeCode) { case PrimitiveTypeCode.Int8: case PrimitiveTypeCode.Int16: case PrimitiveTypeCode.Int32: case PrimitiveTypeCode.Int64: case PrimitiveTypeCode.UInt8: case PrimitiveTypeCode.UInt16: case PrimitiveTypeCode.UInt32: case PrimitiveTypeCode.UInt64: case PrimitiveTypeCode.Float32: case PrimitiveTypeCode.Float64: case PrimitiveTypeCode.Boolean: case PrimitiveTypeCode.Char: return new ConstantExpression(type, this.GetPrimitiveValue(type)); case PrimitiveTypeCode.String: return new ConstantExpression(type, this.GetSerializedString()); default: var typeDef = type.ResolvedType; if (!(typeDef is Dummy)) { if (typeDef.IsEnum) return new ConstantExpression(type, this.GetPrimitiveValue(typeDef.UnderlyingType)); } if (TypeHelper.TypesAreEquivalent(type, this.PEFileToObjectModel.PlatformType.SystemObject)) { ITypeReference/*?*/ underlyingType = this.GetFieldOrPropType(); if (underlyingType == null) return null; return this.ReadSerializedValue(underlyingType); } if (TypeHelper.TypesAreEquivalent(type, this.PEFileToObjectModel.PlatformType.SystemType)) { string/*?*/ typeNameStr = this.GetSerializedString(); if (typeNameStr == null) { return new ConstantExpression(this.PEFileToObjectModel.PlatformType.SystemType, null); } return new TypeOfExpression(this.PEFileToObjectModel, this.PEFileToObjectModel.GetSerializedTypeNameAsTypeReference(typeNameStr)); } var vectorType = type as IArrayTypeReference; if (vectorType != null) { ITypeReference/*?*/ elementType = vectorType.ElementType; if (elementType == null) { this.decodeFailed = true; return null; } int size = this.SignatureMemoryReader.ReadInt32(); if (size == -1) { return new ConstantExpression(vectorType, null); } ExpressionBase[] arrayElements = new ExpressionBase[size]; for (int i = 0; i < size; ++i) { ExpressionBase/*?*/ expr = this.ReadSerializedValue(elementType); if (expr == null) { this.decodeFailed = true; return null; } arrayElements[i] = expr; } return new ArrayExpression(vectorType, new EnumerableArrayWrapper<ExpressionBase, IMetadataExpression>(arrayElements, Dummy.Expression)); } else { // If the metadata is correct, type must be a reference to an enum type. // Problem is, that without resolving this reference, it is not possible to know how many bytes to consume for the enum value // We'll let the host deal with this by guessing ITypeReference underlyingType; switch (this.PEFileToObjectModel.ModuleReader.metadataReaderHost.GuessUnderlyingTypeSizeOfUnresolvableReferenceToEnum(type)) { case 1: underlyingType = this.PEFileToObjectModel.PlatformType.SystemInt8; break; case 2: underlyingType = this.PEFileToObjectModel.PlatformType.SystemInt16; break; case 4: underlyingType = this.PEFileToObjectModel.PlatformType.SystemInt32; break; case 8: underlyingType = this.PEFileToObjectModel.PlatformType.SystemInt64; break; default: this.decodeFailed = true; this.morePermutationsArePossible = false; return new ConstantExpression(type, 0); } return new ConstantExpression(type, this.GetPrimitiveValue(underlyingType)); } } }