//^ [NotDelayed] internal CustomAttributeDecoder( PEFileToObjectModel peFileToObjectModel, MemoryReader signatureMemoryReader, uint customAttributeRowId, IModuleMethodReference attributeConstructor ) : base(peFileToObjectModel, signatureMemoryReader) { //^ this.SignatureMemoryReader = signatureMemoryReader; //TODO: Spec# bug. This assignment should not be necessary. this.CustomAttribute = Dummy.CustomAttribute; //^ base; ushort prolog = this.SignatureMemoryReader.ReadUInt16(); if (prolog != SerializationType.CustomAttributeStart) { return; } List<ExpressionBase> exprList = new List<ExpressionBase>(); IModuleParameterTypeInformation[] modParams = attributeConstructor.RequiredModuleParameterInfos.RawArray; int len = modParams.Length; for (int i = 0; i < len; ++i) { IModuleTypeReference/*?*/ moduleTypeRef = modParams[i].ModuleTypeReference; if (moduleTypeRef == null) { // Error... return; } ExpressionBase/*?*/ argument = this.ReadSerializedValue(moduleTypeRef); if (argument == null) { // Error... this.decodeFailed = true; return; } exprList.Add(argument); } ushort numOfNamedArgs = this.SignatureMemoryReader.ReadUInt16(); FieldOrPropertyNamedArgumentExpression[]/*?*/ namedArgumentArray = null; if (numOfNamedArgs > 0) { namedArgumentArray = new FieldOrPropertyNamedArgumentExpression[numOfNamedArgs]; for (ushort i = 0; i < numOfNamedArgs; ++i) { bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field; IModuleTypeReference/*?*/ memberType = this.GetFieldOrPropType(); if (memberType == null) { // Error... return; } string/*?*/ memberStr = this.GetSerializedString(); if (memberStr == null) return; IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr); ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType); if (value == null) { // Error... return; } IModuleTypeReference/*?*/ moduleTypeRef = attributeConstructor.OwningTypeReference; if (moduleTypeRef == null) { // Error... return; } FieldOrPropertyNamedArgumentExpression namedArg = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeRef, isField, memberType, value); namedArgumentArray[i] = namedArg; } } EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> arguments = TypeCache.EmptyExpressionList; if (exprList.Count > 0) arguments = new EnumerableArrayWrapper<ExpressionBase, IMetadataExpression>(exprList.ToArray(), Dummy.Expression); EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments = TypeCache.EmptyNamedArgumentList; if (namedArgumentArray != null) namedArguments = new EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument>(namedArgumentArray, Dummy.NamedArgument); this.CustomAttribute = new CustomAttribute(this.PEFileToObjectModel, customAttributeRowId, attributeConstructor, arguments, namedArguments); }
/*?*/ SecurityCustomAttribute ReadSecurityAttribute(SecurityAttribute securityAttribute) { string/*?*/ typeNameStr = this.GetSerializedString(); if (typeNameStr == null) return null; IModuleTypeReference/*?*/ moduleTypeReference = this.PEFileToObjectModel.GetSerializedTypeNameAsTypeReference(typeNameStr); if (moduleTypeReference == null) return null; IMethodReference ctorReference = Dummy.MethodReference; ITypeDefinition attributeType = moduleTypeReference.ResolvedType; if (attributeType != Dummy.Type) { foreach (ITypeDefinitionMember member in attributeType.GetMembersNamed(this.PEFileToObjectModel.NameTable.Ctor, false)) { IMethodDefinition/*?*/ method = member as IMethodDefinition; if (method == null) continue; if (!IteratorHelper.EnumerableHasLength(method.Parameters, 1)) continue; //TODO: check that parameter has the right type ctorReference = method; break; } } else { int ctorKey = this.PEFileToObjectModel.NameTable.Ctor.UniqueKey; foreach (ITypeMemberReference mref in this.PEFileToObjectModel.GetMemberReferences()) { IMethodReference/*?*/ methRef = mref as IMethodReference; if (methRef == null) continue; if (methRef.ContainingType.InternedKey != moduleTypeReference.InternedKey) continue; if (methRef.Name.UniqueKey != ctorKey) continue; if (!IteratorHelper.EnumerableHasLength(methRef.Parameters, 1)) continue; //TODO: check that parameter has the right type ctorReference = methRef; break; } } if (ctorReference == Dummy.MethodReference) { ctorReference = new MethodReference(this.PEFileToObjectModel.ModuleReader.metadataReaderHost, moduleTypeReference, CallingConvention.Default|CallingConvention.HasThis, this.PEFileToObjectModel.PlatformType.SystemVoid, this.PEFileToObjectModel.NameTable.Ctor, 0, this.PEFileToObjectModel.PlatformType.SystemSecurityPermissionsSecurityAction); } this.SignatureMemoryReader.ReadCompressedUInt32(); // BlobSize... int numOfNamedArgs = this.SignatureMemoryReader.ReadCompressedUInt32(); FieldOrPropertyNamedArgumentExpression[]/*?*/ namedArgumentArray = null; if (numOfNamedArgs > 0) { namedArgumentArray = new FieldOrPropertyNamedArgumentExpression[numOfNamedArgs]; for (int i = 0; i < numOfNamedArgs; ++i) { bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field; IModuleTypeReference/*?*/ memberType = this.GetFieldOrPropType(); if (memberType == null) return null; string/*?*/ memberStr = this.GetSerializedString(); if (memberStr == null) return null; IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr); ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType); if (value == null) return null; namedArgumentArray[i] = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeReference, isField, memberType, value); } } EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments = TypeCache.EmptyNamedArgumentList; if (namedArgumentArray != null) namedArguments = new EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument>(namedArgumentArray, Dummy.NamedArgument); return new SecurityCustomAttribute(securityAttribute, ctorReference, TypeCache.EmptyExpressionList, namedArguments); }
internal CustomAttributeDecoder(PEFileToObjectModel peFileToObjectModel, MemoryReader signatureMemoryReader, uint customAttributeRowId, IMethodReference attributeConstructor) : base(peFileToObjectModel, signatureMemoryReader) { this.CustomAttribute = Dummy.CustomAttribute; ushort prolog = this.SignatureMemoryReader.ReadUInt16(); if (prolog != SerializationType.CustomAttributeStart) return; int len = attributeConstructor.ParameterCount; ExpressionBase[]/*?*/ exprList = len == 0 ? null : new ExpressionBase[len]; int i = 0; foreach (var parameter in attributeConstructor.Parameters) { var parameterType = parameter.Type; if (parameterType == Dummy.TypeReference) { // Error... return; } ExpressionBase/*?*/ argument = this.ReadSerializedValue(parameterType); if (argument == null) { // Error... this.decodeFailed = true; return; } exprList[i++] = argument; } ushort numOfNamedArgs = this.SignatureMemoryReader.ReadUInt16(); FieldOrPropertyNamedArgumentExpression[]/*?*/ namedArgumentArray = null; if (numOfNamedArgs > 0) { namedArgumentArray = new FieldOrPropertyNamedArgumentExpression[numOfNamedArgs]; for (i = 0; i < numOfNamedArgs; ++i) { bool isField = this.SignatureMemoryReader.ReadByte() == SerializationType.Field; ITypeReference/*?*/ memberType = this.GetFieldOrPropType(); if (memberType == null) { // Error... return; } string/*?*/ memberStr = this.GetSerializedString(); if (memberStr == null) return; IName memberName = this.PEFileToObjectModel.NameTable.GetNameFor(memberStr); ExpressionBase/*?*/ value = this.ReadSerializedValue(memberType); if (value == null) { // Error... return; } ITypeReference/*?*/ moduleTypeRef = attributeConstructor.ContainingType; if (moduleTypeRef == null) { // Error... return; } FieldOrPropertyNamedArgumentExpression namedArg = new FieldOrPropertyNamedArgumentExpression(memberName, moduleTypeRef, isField, memberType, value); namedArgumentArray[i] = namedArg; } } EnumerableArrayWrapper<ExpressionBase, IMetadataExpression> arguments = TypeCache.EmptyExpressionList; if (exprList != null) arguments = new EnumerableArrayWrapper<ExpressionBase, IMetadataExpression>(exprList, Dummy.Expression); EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument> namedArguments = TypeCache.EmptyNamedArgumentList; if (namedArgumentArray != null) namedArguments = new EnumerableArrayWrapper<FieldOrPropertyNamedArgumentExpression, IMetadataNamedArgument>(namedArgumentArray, Dummy.NamedArgument); this.CustomAttribute = peFileToObjectModel.ModuleReader.metadataReaderHost.Rewrite(peFileToObjectModel.Module, new CustomAttribute(peFileToObjectModel, customAttributeRowId, attributeConstructor, arguments, namedArguments)); }