private bool IsWindowsAttributeUsageAttribute(EntityHandle targetType, CustomAttributeHandle attributeHandle) { // Check for Windows.Foundation.Metadata.AttributeUsageAttribute. // WinMD rules: // - The attribute is only applicable on TypeDefs. // - Constructor must be a MemberRef with TypeRef. if (targetType.Kind != HandleKind.TypeDefinition) { return(false); } var attributeCtor = CustomAttributeTable.GetConstructor(attributeHandle); if (attributeCtor.Kind != HandleKind.MemberReference) { return(false); } var attributeType = MemberRefTable.GetClass((MemberReferenceHandle)attributeCtor); if (attributeType.Kind != HandleKind.TypeReference) { return(false); } var attributeTypeRef = (TypeReferenceHandle)attributeType; return(StringStream.EqualsRaw(TypeRefTable.GetName(attributeTypeRef), "AttributeUsageAttribute") && StringStream.EqualsRaw(TypeRefTable.GetNamespace(attributeTypeRef), "Windows.Foundation.Metadata")); }
internal CustomAttributeValueTreatment CalculateCustomAttributeValueTreatment(CustomAttributeHandle handle) { Debug.Assert(_metadataKind != MetadataKind.Ecma335); var parent = CustomAttributeTable.GetParent(handle); // Check for Windows.Foundation.Metadata.AttributeUsageAttribute. // WinMD rules: // - The attribute is only applicable on TypeDefs. // - Constructor must be a MemberRef with TypeRef. if (!IsWindowsAttributeUsageAttribute(parent, handle)) { return(CustomAttributeValueTreatment.None); } var targetTypeDef = (TypeDefinitionHandle)parent; if (StringStream.EqualsRaw(TypeDefTable.GetNamespace(targetTypeDef), "Windows.Foundation.Metadata")) { if (StringStream.EqualsRaw(TypeDefTable.GetName(targetTypeDef), "VersionAttribute")) { return(CustomAttributeValueTreatment.AttributeUsageVersionAttribute); } if (StringStream.EqualsRaw(TypeDefTable.GetName(targetTypeDef), "DeprecatedAttribute")) { return(CustomAttributeValueTreatment.AttributeUsageDeprecatedAttribute); } } bool allowMultiple = HasAttribute(targetTypeDef, "Windows.Foundation.Metadata", "AllowMultipleAttribute"); return(allowMultiple ? CustomAttributeValueTreatment.AttributeUsageAllowMultiple : CustomAttributeValueTreatment.AttributeUsageAllowSingle); }
internal void WriteHasCustomAttribute(int token) { int encodedToken = CustomAttributeTable.EncodeHasCustomAttribute(token); if (bigHasCustomAttribute) { Write(encodedToken); } else { Write((short)encodedToken); } }
void EncodeCustomAttributeTable(CustomAttributeTable table) { int index = 0; foreach (CustomAttributeRow row in table.Rows) { this.asm.ALIGN(Assembly.OBJECT_ALIGNMENT); this.asm.LABEL(moduleName + " CustomAttributeRow#" + index); this.asm.AddObjectFields(typeof(SharpOS.AOT.Metadata.CustomAttributeRow).ToString()); this.asm.DATA(row.Parent.ToUInt()); this.asm.DATA(row.Type.ToUInt()); this.asm.DATA(row.Value); ++index; } this.MetadataArray("CustomAttribute", table); }
/// <summary> /// Returns the type definition or reference handle of the attribute type. /// </summary> /// <returns><see cref="TypeDefinitionHandle"/> or <see cref="TypeReferenceHandle"/> or nil token if the metadata is invalid and the type can't be determined.</returns> private EntityHandle GetAttributeTypeRaw(CustomAttributeHandle handle) { var ctor = CustomAttributeTable.GetConstructor(handle); if (ctor.Kind == HandleKind.MethodDefinition) { return(GetDeclaringType((MethodDefinitionHandle)ctor)); } if (ctor.Kind == HandleKind.MemberReference) { // In general the parent can be MethodDef, ModuleRef, TypeDef, TypeRef, or TypeSpec. // For attributes only TypeDef and TypeRef are applicable. EntityHandle typeDefOrRef = MemberRefTable.GetClass((MemberReferenceHandle)ctor); HandleKind handleType = typeDefOrRef.Kind; if (handleType == HandleKind.TypeReference || handleType == HandleKind.TypeDefinition) { return(typeDefOrRef); } } return(default(EntityHandle)); }
public virtual void VisitCustomAttributeTable(CustomAttributeTable table) { }
public void Read(ReaderContext ctxt) { var reader = ctxt.GetTablesReader(); var actualReserved0 = reader.ReadUInt32(); if (actualReserved0 != reserved0) throw new PEException("invalid MetadataTable header"); var actualMajorVersion = reader.ReadByte(); if (actualMajorVersion != majorVersion) throw new PEException("invalid MetadataTable header"); var actualMinorVersion = reader.ReadByte(); if (actualMinorVersion != minorVersion) throw new PEException("invalid MetadataTable header"); var heapSizes = reader.ReadByte(); IsStringStreamBig = (heapSizes & 0x01) != 0; IsGuidStreamBig = (heapSizes & 0x02) != 0; IsBlobStreamBig = (heapSizes & 0x04) != 0; Reserved1 = reader.ReadByte(); var valid = new IntSet64(reader.ReadUInt64()); var sorted = new IntSet64(reader.ReadUInt64()); for (var i = 0; i < 64; i++) { var numRows = 0; if (valid[i]) numRows = (int)reader.ReadUInt32(); switch ((TableTag)i) { case TableTag.Module: ModuleTable = new ModuleTable(numRows); break; case TableTag.Assembly: AssemblyTable = new AssemblyTable(numRows); break; case TableTag.AssemblyOS: AssemblyOSTable = new AssemblyOSTable(numRows); break; case TableTag.AssemblyProcessor: AssemblyProcessorTable = new AssemblyProcessorTable(numRows); break; case TableTag.AssemblyRef: AssemblyRefTable = new AssemblyRefTable(numRows); break; case TableTag.AssemblyRefOS: AssemblyRefOSTable = new AssemblyRefOSTable(numRows); break; case TableTag.AssemblyRefProcessor: AssemblyRefProcessorTable = new AssemblyRefProcessorTable(numRows); break; case TableTag.ClassLayout: ClassLayoutTable = new ClassLayoutTable(numRows); break; case TableTag.Constant: ConstantTable = new ConstantTable(numRows); break; case TableTag.CustomAttribute: CustomAttributeTable = new CustomAttributeTable(numRows); break; case TableTag.DeclSecurity: DeclSecurityTable = new DeclSecurityTable(numRows); break; case TableTag.EventMap: EventMapTable = new EventMapTable(numRows); break; case TableTag.Event: EventTable = new EventTable(numRows); break; case TableTag.ExportedType: ExportedTypeTable = new ExportedTypeTable(numRows); break; case TableTag.Field: FieldTable = new FieldTable(numRows); break; case TableTag.FieldLayout: FieldLayoutTable = new FieldLayoutTable(numRows); break; case TableTag.FieldMarshal: FieldMarshalTable = new FieldMarshalTable(numRows); break; case TableTag.FieldRVA: FieldRVATable = new FieldRVATable(numRows); break; case TableTag.File: FileTable = new FileTable(numRows); break; case TableTag.GenericParam: GenericParamTable = new GenericParamTable(numRows); break; case TableTag.GenericParamConstraint: GenericParamConstraintTable = new GenericParamConstraintTable(numRows); break; case TableTag.ImplMap: ImplMapTable = new ImplMapTable(numRows); break; case TableTag.InterfaceImpl: InterfaceImplTable = new InterfaceImplTable(numRows); break; case TableTag.ManifestResource: ManifestResourceTable = new ManifestResourceTable(numRows); break; case TableTag.MemberRef: MemberRefTable = new MemberRefTable(numRows); break; case TableTag.MethodDef: MethodDefTable = new MethodDefTable(numRows); break; case TableTag.MethodImpl: MethodImplTable = new MethodImplTable(numRows); break; case TableTag.MethodSemantics: MethodSemanticsTable = new MethodSemanticsTable(numRows); break; case TableTag.MethodSpec: MethodSpecTable = new MethodSpecTable(numRows); break; case TableTag.ModuleRef: ModuleRefTable = new ModuleRefTable(numRows); break; case TableTag.NestedClass: NestedClassTable = new NestedClassTable(numRows); break; case TableTag.Param: ParamTable = new ParamTable(numRows); break; case TableTag.Property: PropertyTable = new PropertyTable(numRows); break; case TableTag.PropertyMap: PropertyMapTable = new PropertyMapTable(numRows); break; case TableTag.StandAloneSig: StandAloneSigTable = new StandAloneSigTable(numRows); break; case TableTag.TypeDef: TypeDefTable = new TypeDefTable(numRows); break; case TableTag.TypeRef: TypeRefTable = new TypeRefTable(numRows); break; case TableTag.TypeSpec: TypeSpecTable = new TypeSpecTable(numRows); break; default: // Ignore break; } } DetermineIndexCodingSizes(); for (var i = 0; i < 64; i++) { if (valid[i]) { switch ((TableTag)i) { case TableTag.Module: ModuleTable.Read(ctxt, reader); break; case TableTag.Assembly: AssemblyTable.Read(ctxt, reader); break; case TableTag.AssemblyOS: AssemblyOSTable.Read(ctxt, reader); break; case TableTag.AssemblyProcessor: AssemblyProcessorTable.Read(ctxt, reader); break; case TableTag.AssemblyRef: AssemblyRefTable.Read(ctxt, reader); break; case TableTag.AssemblyRefOS: AssemblyRefOSTable.Read(ctxt, reader); break; case TableTag.AssemblyRefProcessor: AssemblyRefProcessorTable.Read(ctxt, reader); break; case TableTag.ClassLayout: ClassLayoutTable.Read(ctxt, reader); break; case TableTag.Constant: ConstantTable.Read(ctxt, reader); break; case TableTag.CustomAttribute: CustomAttributeTable.Read(ctxt, reader); break; case TableTag.DeclSecurity: DeclSecurityTable.Read(ctxt, reader); break; case TableTag.EventMap: EventMapTable.Read(ctxt, reader); break; case TableTag.Event: EventTable.Read(ctxt, reader); break; case TableTag.ExportedType: ExportedTypeTable.Read(ctxt, reader); break; case TableTag.Field: FieldTable.Read(ctxt, reader); break; case TableTag.FieldLayout: FieldLayoutTable.Read(ctxt, reader); break; case TableTag.FieldMarshal: FieldMarshalTable.Read(ctxt, reader); break; case TableTag.FieldRVA: FieldRVATable.Read(ctxt, reader); break; case TableTag.File: FileTable.Read(ctxt, reader); break; case TableTag.GenericParam: GenericParamTable.Read(ctxt, reader); break; case TableTag.GenericParamConstraint: GenericParamConstraintTable.Read(ctxt, reader); break; case TableTag.ImplMap: ImplMapTable.Read(ctxt, reader); break; case TableTag.InterfaceImpl: InterfaceImplTable.Read(ctxt, reader); break; case TableTag.ManifestResource: ManifestResourceTable.Read(ctxt, reader); break; case TableTag.MemberRef: MemberRefTable.Read(ctxt, reader); break; case TableTag.MethodDef: MethodDefTable.Read(ctxt, reader); break; case TableTag.MethodImpl: MethodImplTable.Read(ctxt, reader); break; case TableTag.MethodSemantics: MethodSemanticsTable.Read(ctxt, reader); break; case TableTag.MethodSpec: MethodSpecTable.Read(ctxt, reader); break; case TableTag.ModuleRef: ModuleRefTable.Read(ctxt, reader); break; case TableTag.NestedClass: NestedClassTable.Read(ctxt, reader); break; case TableTag.Param: ParamTable.Read(ctxt, reader); break; case TableTag.Property: PropertyTable.Read(ctxt, reader); break; case TableTag.PropertyMap: PropertyMapTable.Read(ctxt, reader); break; case TableTag.StandAloneSig: StandAloneSigTable.Read(ctxt, reader); break; case TableTag.TypeDef: TypeDefTable.Read(ctxt, reader); break; case TableTag.TypeRef: TypeRefTable.Read(ctxt, reader); break; case TableTag.TypeSpec: TypeSpecTable.Read(ctxt, reader); break; default: throw new PEException("unexpected table tag in MetadataTable body"); } } } ModuleTable.ResolveIndexes(ctxt); TypeRefTable.ResolveIndexes(ctxt); TypeDefTable.ResolveIndexes(ctxt); FieldTable.ResolveIndexes(ctxt); MethodDefTable.ResolveIndexes(ctxt); ParamTable.ResolveIndexes(ctxt); InterfaceImplTable.ResolveIndexes(ctxt); MemberRefTable.ResolveIndexes(ctxt); ConstantTable.ResolveIndexes(ctxt); CustomAttributeTable.ResolveIndexes(ctxt); FieldMarshalTable.ResolveIndexes(ctxt); DeclSecurityTable.ResolveIndexes(ctxt); ClassLayoutTable.ResolveIndexes(ctxt); FieldLayoutTable.ResolveIndexes(ctxt); StandAloneSigTable.ResolveIndexes(ctxt); EventMapTable.ResolveIndexes(ctxt); EventTable.ResolveIndexes(ctxt); PropertyMapTable.ResolveIndexes(ctxt); PropertyTable.ResolveIndexes(ctxt); MethodSemanticsTable.ResolveIndexes(ctxt); MethodImplTable.ResolveIndexes(ctxt); ModuleRefTable.ResolveIndexes(ctxt); TypeSpecTable.ResolveIndexes(ctxt); ImplMapTable.ResolveIndexes(ctxt); FieldRVATable.ResolveIndexes(ctxt); AssemblyTable.ResolveIndexes(ctxt); AssemblyProcessorTable.ResolveIndexes(ctxt); AssemblyOSTable.ResolveIndexes(ctxt); AssemblyRefTable.ResolveIndexes(ctxt); AssemblyRefProcessorTable.ResolveIndexes(ctxt); AssemblyRefOSTable.ResolveIndexes(ctxt); FileTable.ResolveIndexes(ctxt); ExportedTypeTable.ResolveIndexes(ctxt); ManifestResourceTable.ResolveIndexes(ctxt); NestedClassTable.ResolveIndexes(ctxt); GenericParamTable.ResolveIndexes(ctxt); MethodSpecTable.ResolveIndexes(ctxt); GenericParamConstraintTable.ResolveIndexes(ctxt); }
public virtual void VisitCustomAttributeTable(CustomAttributeTable table) { }
public void Read(ReaderContext ctxt) { var reader = ctxt.GetTablesReader(); var actualReserved0 = reader.ReadUInt32(); if (actualReserved0 != reserved0) { throw new PEException("invalid MetadataTable header"); } var actualMajorVersion = reader.ReadByte(); if (actualMajorVersion != majorVersion) { throw new PEException("invalid MetadataTable header"); } var actualMinorVersion = reader.ReadByte(); if (actualMinorVersion != minorVersion) { throw new PEException("invalid MetadataTable header"); } var heapSizes = reader.ReadByte(); IsStringStreamBig = (heapSizes & 0x01) != 0; IsGuidStreamBig = (heapSizes & 0x02) != 0; IsBlobStreamBig = (heapSizes & 0x04) != 0; Reserved1 = reader.ReadByte(); var valid = new IntSet64(reader.ReadUInt64()); var sorted = new IntSet64(reader.ReadUInt64()); for (var i = 0; i < 64; i++) { var numRows = 0; if (valid[i]) { numRows = (int)reader.ReadUInt32(); } switch ((TableTag)i) { case TableTag.Module: ModuleTable = new ModuleTable(numRows); break; case TableTag.Assembly: AssemblyTable = new AssemblyTable(numRows); break; case TableTag.AssemblyOS: AssemblyOSTable = new AssemblyOSTable(numRows); break; case TableTag.AssemblyProcessor: AssemblyProcessorTable = new AssemblyProcessorTable(numRows); break; case TableTag.AssemblyRef: AssemblyRefTable = new AssemblyRefTable(numRows); break; case TableTag.AssemblyRefOS: AssemblyRefOSTable = new AssemblyRefOSTable(numRows); break; case TableTag.AssemblyRefProcessor: AssemblyRefProcessorTable = new AssemblyRefProcessorTable(numRows); break; case TableTag.ClassLayout: ClassLayoutTable = new ClassLayoutTable(numRows); break; case TableTag.Constant: ConstantTable = new ConstantTable(numRows); break; case TableTag.CustomAttribute: CustomAttributeTable = new CustomAttributeTable(numRows); break; case TableTag.DeclSecurity: DeclSecurityTable = new DeclSecurityTable(numRows); break; case TableTag.EventMap: EventMapTable = new EventMapTable(numRows); break; case TableTag.Event: EventTable = new EventTable(numRows); break; case TableTag.ExportedType: ExportedTypeTable = new ExportedTypeTable(numRows); break; case TableTag.Field: FieldTable = new FieldTable(numRows); break; case TableTag.FieldLayout: FieldLayoutTable = new FieldLayoutTable(numRows); break; case TableTag.FieldMarshal: FieldMarshalTable = new FieldMarshalTable(numRows); break; case TableTag.FieldRVA: FieldRVATable = new FieldRVATable(numRows); break; case TableTag.File: FileTable = new FileTable(numRows); break; case TableTag.GenericParam: GenericParamTable = new GenericParamTable(numRows); break; case TableTag.GenericParamConstraint: GenericParamConstraintTable = new GenericParamConstraintTable(numRows); break; case TableTag.ImplMap: ImplMapTable = new ImplMapTable(numRows); break; case TableTag.InterfaceImpl: InterfaceImplTable = new InterfaceImplTable(numRows); break; case TableTag.ManifestResource: ManifestResourceTable = new ManifestResourceTable(numRows); break; case TableTag.MemberRef: MemberRefTable = new MemberRefTable(numRows); break; case TableTag.MethodDef: MethodDefTable = new MethodDefTable(numRows); break; case TableTag.MethodImpl: MethodImplTable = new MethodImplTable(numRows); break; case TableTag.MethodSemantics: MethodSemanticsTable = new MethodSemanticsTable(numRows); break; case TableTag.MethodSpec: MethodSpecTable = new MethodSpecTable(numRows); break; case TableTag.ModuleRef: ModuleRefTable = new ModuleRefTable(numRows); break; case TableTag.NestedClass: NestedClassTable = new NestedClassTable(numRows); break; case TableTag.Param: ParamTable = new ParamTable(numRows); break; case TableTag.Property: PropertyTable = new PropertyTable(numRows); break; case TableTag.PropertyMap: PropertyMapTable = new PropertyMapTable(numRows); break; case TableTag.StandAloneSig: StandAloneSigTable = new StandAloneSigTable(numRows); break; case TableTag.TypeDef: TypeDefTable = new TypeDefTable(numRows); break; case TableTag.TypeRef: TypeRefTable = new TypeRefTable(numRows); break; case TableTag.TypeSpec: TypeSpecTable = new TypeSpecTable(numRows); break; default: // Ignore break; } } DetermineIndexCodingSizes(); for (var i = 0; i < 64; i++) { if (valid[i]) { switch ((TableTag)i) { case TableTag.Module: ModuleTable.Read(ctxt, reader); break; case TableTag.Assembly: AssemblyTable.Read(ctxt, reader); break; case TableTag.AssemblyOS: AssemblyOSTable.Read(ctxt, reader); break; case TableTag.AssemblyProcessor: AssemblyProcessorTable.Read(ctxt, reader); break; case TableTag.AssemblyRef: AssemblyRefTable.Read(ctxt, reader); break; case TableTag.AssemblyRefOS: AssemblyRefOSTable.Read(ctxt, reader); break; case TableTag.AssemblyRefProcessor: AssemblyRefProcessorTable.Read(ctxt, reader); break; case TableTag.ClassLayout: ClassLayoutTable.Read(ctxt, reader); break; case TableTag.Constant: ConstantTable.Read(ctxt, reader); break; case TableTag.CustomAttribute: CustomAttributeTable.Read(ctxt, reader); break; case TableTag.DeclSecurity: DeclSecurityTable.Read(ctxt, reader); break; case TableTag.EventMap: EventMapTable.Read(ctxt, reader); break; case TableTag.Event: EventTable.Read(ctxt, reader); break; case TableTag.ExportedType: ExportedTypeTable.Read(ctxt, reader); break; case TableTag.Field: FieldTable.Read(ctxt, reader); break; case TableTag.FieldLayout: FieldLayoutTable.Read(ctxt, reader); break; case TableTag.FieldMarshal: FieldMarshalTable.Read(ctxt, reader); break; case TableTag.FieldRVA: FieldRVATable.Read(ctxt, reader); break; case TableTag.File: FileTable.Read(ctxt, reader); break; case TableTag.GenericParam: GenericParamTable.Read(ctxt, reader); break; case TableTag.GenericParamConstraint: GenericParamConstraintTable.Read(ctxt, reader); break; case TableTag.ImplMap: ImplMapTable.Read(ctxt, reader); break; case TableTag.InterfaceImpl: InterfaceImplTable.Read(ctxt, reader); break; case TableTag.ManifestResource: ManifestResourceTable.Read(ctxt, reader); break; case TableTag.MemberRef: MemberRefTable.Read(ctxt, reader); break; case TableTag.MethodDef: MethodDefTable.Read(ctxt, reader); break; case TableTag.MethodImpl: MethodImplTable.Read(ctxt, reader); break; case TableTag.MethodSemantics: MethodSemanticsTable.Read(ctxt, reader); break; case TableTag.MethodSpec: MethodSpecTable.Read(ctxt, reader); break; case TableTag.ModuleRef: ModuleRefTable.Read(ctxt, reader); break; case TableTag.NestedClass: NestedClassTable.Read(ctxt, reader); break; case TableTag.Param: ParamTable.Read(ctxt, reader); break; case TableTag.Property: PropertyTable.Read(ctxt, reader); break; case TableTag.PropertyMap: PropertyMapTable.Read(ctxt, reader); break; case TableTag.StandAloneSig: StandAloneSigTable.Read(ctxt, reader); break; case TableTag.TypeDef: TypeDefTable.Read(ctxt, reader); break; case TableTag.TypeRef: TypeRefTable.Read(ctxt, reader); break; case TableTag.TypeSpec: TypeSpecTable.Read(ctxt, reader); break; default: throw new PEException("unexpected table tag in MetadataTable body"); } } } ModuleTable.ResolveIndexes(ctxt); TypeRefTable.ResolveIndexes(ctxt); TypeDefTable.ResolveIndexes(ctxt); FieldTable.ResolveIndexes(ctxt); MethodDefTable.ResolveIndexes(ctxt); ParamTable.ResolveIndexes(ctxt); InterfaceImplTable.ResolveIndexes(ctxt); MemberRefTable.ResolveIndexes(ctxt); ConstantTable.ResolveIndexes(ctxt); CustomAttributeTable.ResolveIndexes(ctxt); FieldMarshalTable.ResolveIndexes(ctxt); DeclSecurityTable.ResolveIndexes(ctxt); ClassLayoutTable.ResolveIndexes(ctxt); FieldLayoutTable.ResolveIndexes(ctxt); StandAloneSigTable.ResolveIndexes(ctxt); EventMapTable.ResolveIndexes(ctxt); EventTable.ResolveIndexes(ctxt); PropertyMapTable.ResolveIndexes(ctxt); PropertyTable.ResolveIndexes(ctxt); MethodSemanticsTable.ResolveIndexes(ctxt); MethodImplTable.ResolveIndexes(ctxt); ModuleRefTable.ResolveIndexes(ctxt); TypeSpecTable.ResolveIndexes(ctxt); ImplMapTable.ResolveIndexes(ctxt); FieldRVATable.ResolveIndexes(ctxt); AssemblyTable.ResolveIndexes(ctxt); AssemblyProcessorTable.ResolveIndexes(ctxt); AssemblyOSTable.ResolveIndexes(ctxt); AssemblyRefTable.ResolveIndexes(ctxt); AssemblyRefProcessorTable.ResolveIndexes(ctxt); AssemblyRefOSTable.ResolveIndexes(ctxt); FileTable.ResolveIndexes(ctxt); ExportedTypeTable.ResolveIndexes(ctxt); ManifestResourceTable.ResolveIndexes(ctxt); NestedClassTable.ResolveIndexes(ctxt); GenericParamTable.ResolveIndexes(ctxt); MethodSpecTable.ResolveIndexes(ctxt); GenericParamConstraintTable.ResolveIndexes(ctxt); }
private static bool HasAllowMultipleAttribute(CustomAttributeTable.Record[] customAttributes, int i, int ctorWindowsFoundationMetadataAllowMultipleAttribute) { // we can assume that the CustomAttribute table is sorted, because we've checked the Sorted flag earlier int owner = customAttributes[i].Parent; while (i > 0 && customAttributes[i - 1].Parent == owner) { i--; } while (i < customAttributes.Length && customAttributes[i].Parent == owner) { if (customAttributes[i].Type == ctorWindowsFoundationMetadataAllowMultipleAttribute) { return true; } i++; } return false; }
void ReadCustomAttributes() { if (!m_tHeap.HasTable(CustomAttributeTable.RId)) { return; } CustomAttributeTable caTable = m_tableReader.GetCustomAttributeTable(); for (int i = 0; i < caTable.Rows.Count; i++) { CustomAttributeRow caRow = caTable [i]; MethodReference ctor; if (caRow.Type.RID == 0) { continue; } if (caRow.Type.TokenType == TokenType.Method) { ctor = GetMethodDefAt(caRow.Type.RID); } else { ctor = GetMemberRefAt(caRow.Type.RID, new GenericContext()) as MethodReference; } CustomAttrib ca = m_sigReader.GetCustomAttrib(caRow.Value, ctor); CustomAttribute cattr = BuildCustomAttribute(ctor, m_root.Streams.BlobHeap.Read(caRow.Value), ca); if (caRow.Parent.RID == 0) { continue; } ICustomAttributeProvider owner = null; switch (caRow.Parent.TokenType) { case TokenType.Assembly: owner = this.Module.Assembly; break; case TokenType.Module: owner = this.Module; break; case TokenType.TypeDef: owner = GetTypeDefAt(caRow.Parent.RID); break; case TokenType.TypeRef: owner = GetTypeRefAt(caRow.Parent.RID); break; case TokenType.Field: owner = GetFieldDefAt(caRow.Parent.RID); break; case TokenType.Method: owner = GetMethodDefAt(caRow.Parent.RID); break; case TokenType.Property: owner = GetPropertyDefAt(caRow.Parent.RID); break; case TokenType.Event: owner = GetEventDefAt(caRow.Parent.RID); break; case TokenType.Param: owner = GetParamDefAt(caRow.Parent.RID); break; case TokenType.GenericParam: owner = GetGenericParameterAt(caRow.Parent.RID); break; default: //TODO: support other ? break; } if (owner != null) { owner.CustomAttributes.Add(cattr); } } }