public void RowEnumerationTest() { var rawRow = new uint[] { 0x002E, 0x000B, 0x0029 }; var row = new CustomAttributeRow(rawRow[0], rawRow[1], rawRow[2]); RowTestUtils.VerifyRowColumnEnumeration(rawRow, row); }
/// <summary> /// Populates the <see cref="RuntimeAttribute"/> with the values in <paramref name="car"/>. /// </summary> /// <param name="module">The metadata module, which defines the attribute.</param> /// <param name="car">The custom attribute row From metadata.</param> public RuntimeAttribute(IMetadataModule module, CustomAttributeRow car) { _attribute = null; _attributeBlob = car.ValueBlobIdx; _ctor = car.TypeIdx; _module = module; }
public int Compare(object x, object y) { CustomAttributeRow a = x as CustomAttributeRow; CustomAttributeRow b = y as CustomAttributeRow; return(Comparer.Default.Compare( Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, a.Parent), Utilities.CompressMetadataToken(CodedIndex.HasCustomAttribute, b.Parent))); }
public override void FromRawData(byte [] buff, int offs, int numRows) { for (int i = numRows; --i >= 0;) { Row row = new CustomAttributeRow(this); row.FromRawData(buff, offs); Add(row); offs += CustomAttributeRow.LogicalSize; } }
private void AddCustomAttribute(MetadataToken ownerToken, CustomAttribute attribute) { var table = Metadata.TablesStream.GetSortedTable <CustomAttribute, CustomAttributeRow>(TableIndex.CustomAttribute); var encoder = Metadata.TablesStream.GetIndexEncoder(CodedIndex.HasCustomAttribute); var row = new CustomAttributeRow( encoder.EncodeToken(ownerToken), AddCustomAttributeType(attribute.Constructor), Metadata.BlobStream.GetBlobIndex(this, attribute.Signature, DiagnosticBag)); table.Add(attribute, row); }
/// <summary> /// Reads the specified token. /// </summary> /// <param name="token">The token.</param> /// <param name="result">The result.</param> public void Read(TokenTypes token, out CustomAttributeRow result) { if ((token & TokenTypes.TableMask) != TokenTypes.CustomAttribute) { throw new ArgumentException("Invalid token type for CustomAttributeRow.", "token"); } using (BinaryReader reader = CreateReaderForToken(token)) { result = new CustomAttributeRow(ReadIndexValue(reader, IndexType.HasCustomAttribute), ReadIndexValue(reader, IndexType.CustomAttributeType), ReadIndexValue(reader, IndexType.BlobHeap)); } }
internal static string AttributeRowToString(CustomAttributeRow row) { TableIndex parentTableIndex, constructorTableIndex; MetadataTokens.TryGetTableIndex(row.ParentToken.Kind, out parentTableIndex); MetadataTokens.TryGetTableIndex(row.ConstructorToken.Kind, out constructorTableIndex); return string.Format( "new CustomAttributeRow(Handle({0}, TableIndex.{1}), Handle({2}, TableIndex.{3}))", MetadataTokens.GetRowNumber(row.ParentToken), parentTableIndex, MetadataTokens.GetRowNumber(row.ConstructorToken), constructorTableIndex); }
void IMetadataProvider.Read(TokenTypes token, out CustomAttributeRow result) { TableHeap theap = (TableHeap)_streams[(int)HeapType.Tables]; theap.Read(token, out result); }
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); } } }
internal static string AttributeRowToString(CustomAttributeRow row) { TableIndex parentTableIndex, constructorTableIndex; MetadataTokens.TryGetTableIndex(row.ParentToken.Kind, out parentTableIndex); MetadataTokens.TryGetTableIndex(row.ConstructorToken.Kind, out constructorTableIndex); return string.Format( "new CustomAttributeRow(Handle({0}, TableIndex.{1}), Handle({2}, TableIndex.{3}))", MetadataTokens.GetRowNumber(row.ParentToken), parentTableIndex, MetadataTokens.GetRowNumber(row.ConstructorToken), constructorTableIndex); }
public virtual void VisitCustomAttributeRow(CustomAttributeRow row) { }
private CustomAttributeResolver(CustomAttributeRow row, MetadataSystem metadata) { _row = row; _metadata = metadata; }
/// <summary> /// Loads all custom attributes from the assembly. /// </summary> private void LoadCustomAttributes() { Token maxToken = GetMaxTokenValue(TableType.CustomAttribute); foreach (Token token in new Token(TableType.CustomAttribute, 1).Upto(maxToken)) { CustomAttributeRow row = metadataProvider.ReadCustomAttributeRow(token); Token owner = row.Parent; RuntimeMethod ctorMethod; switch (row.Type.Table) { case TableType.MethodDef: ctorMethod = methods[row.Type.RID - 1]; break; case TableType.MemberRef: ctorMethod = memberRef[row.Type.RID - 1] as RuntimeMethod; break; default: throw new NotImplementedException(); } RuntimeAttribute runtimeAttribute = new RuntimeAttribute(this, row.Type, ctorMethod, row.Value); // The following switch matches the AttributeTargets enumeration against // metadata tables, which make valid targets for an attribute. switch (owner.Table) { case TableType.Assembly: // AttributeTargets.Assembly break; case TableType.TypeDef: // AttributeTargets.Class // AttributeTargets.Delegate // AttributeTargets.Enum // AttributeTargets.Interface // AttributeTargets.Struct types[owner.RID - 1].CustomAttributes.Add(runtimeAttribute); break; case TableType.MethodDef: // AttributeTargets.Constructor // AttributeTargets.Method methods[owner.RID - 1].CustomAttributes.Add(runtimeAttribute); break; case TableType.Event: // AttributeTargets.Event break; case TableType.Field: // AttributeTargets.Field fields[owner.RID - 1].CustomAttributes.Add(runtimeAttribute); break; case TableType.GenericParam: // AttributeTargets.GenericParameter break; case TableType.Module: // AttributeTargets.Module break; case TableType.Param: // AttributeTargets.Parameter // AttributeTargets.ReturnValue break; case TableType.Property: // AttributeTargets.StackFrameIndex break; //default: // throw new NotImplementedException(); } } }
/// <summary> /// Creates a custom attribute from a custom attribute metadata row. /// </summary> /// <param name="parentModule">The module that contains the custom attribute.</param> /// <param name="token">The token to initialize the custom attribute for.</param> /// <param name="row">The metadata table row to base the custom attribute on.</param> public SerializedCustomAttribute(SerializedModuleDefinition parentModule, MetadataToken token, CustomAttributeRow row) : base(token) { _parentModule = parentModule ?? throw new ArgumentNullException(nameof(parentModule)); _row = row; }
public static CustomAttribute Resolve(CustomAttributeRow row, MetadataSystem metadata) { var resolver = new CustomAttributeResolver(row, metadata); return(new CustomAttribute(resolver)); }
public CustomAttributeRowExt(IMetadataProvider metadata, CustomAttributeRow row) : base(metadata) { this.row = row; }
public virtual void VisitCustomAttributeRow(CustomAttributeRow row) { }
private static string AttributeRowToString(CustomAttributeRow row) { return string.Format( "new CustomAttributeRow(Handle({0}, TableIndices.{1}), Handle({2}, TableIndices.{3}))", MetadataTokens.GetRowNumber(row.ParentToken), MetadataTokens.GetTableIndex(row.ParentToken), MetadataTokens.GetRowNumber(row.ConstructorToken), MetadataTokens.GetTableIndex(row.ConstructorToken)); }