Class MetadataTable<TRow>
- Namespace
- AsmResolver.PE.DotNet.Metadata.Tables
- Assembly
- AsmResolver.PE.dll
Provides a base implementation of a metadata table in the table stream of a managed executable file.
public class MetadataTable<TRow> : SegmentBase, IMetadataTable, ICollection, ISegment, IOffsetProvider, IWritable, ICollection<TRow>, IEnumerable<TRow>, IEnumerable where TRow : struct, IMetadataRowType Parameters
- TRow
- The type of rows that this table stores. 
- Inheritance
- 
      
      
      MetadataTable<TRow>
- Implements
- 
      
      
      
      
      
      ICollection<TRow>IEnumerable<TRow>
- Derived
- Inherited Members
Constructors
MetadataTable(TableIndex, TableLayout)
Creates a new metadata table using the provided layout.
public MetadataTable(TableIndex tableIndex, TableLayout layout)Parameters
- tableIndexTableIndex
- The index of the table. 
- layoutTableLayout
- The layout of the table. 
MetadataTable(TableIndex, TableLayout, bool)
Creates a new metadata table using the provided layout.
public MetadataTable(TableIndex tableIndex, TableLayout layout, bool isSorted)Parameters
- tableIndexTableIndex
- The index of the table. 
- layoutTableLayout
- The layout of the table. 
- isSortedbool
- Indicates the table is sorted or not. 
Properties
Capacity
Gets or sets the total number of rows that the underlying array can store.
public int Capacity { get; set; }Property Value
Count
Gets the number of elements contained in the ICollection<T>.
public virtual int Count { get; }Property Value
- int
- The number of elements contained in the ICollection<T>. 
IsInitialized
Gets a value indicating the Rows property is initialized or not.
protected bool IsInitialized { get; }Property Value
IsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
public bool IsReadOnly { get; }Property Value
- bool
- true if the ICollection<T> is read-only; otherwise, false. 
IsSorted
Gets or sets a value indicating whether the table is considered sorted.
public bool IsSorted { get; set; }Property Value
IsSynchronized
Gets a value indicating whether access to the ICollection is synchronized (thread safe).
public bool IsSynchronized { get; }Property Value
- bool
- true if access to the ICollection is synchronized (thread safe); otherwise, false. 
this[int]
Represents a metadata table stored in the tables stream of a managed executable.
public TRow this[int index] { get; set; }Parameters
- indexint
Property Value
- TRow
Layout
Gets the layout of the table.
public TableLayout Layout { get; }Property Value
Rows
Gets the internal list of rows that are stored in the metadata table.
protected RefList<TRow> Rows { get; }Property Value
- RefList<TRow>
SyncRoot
Gets an object that can be used to synchronize access to the ICollection.
public object SyncRoot { get; }Property Value
- object
- An object that can be used to synchronize access to the ICollection. 
TableIndex
Gets the index of the table in the tables stream.
public TableIndex TableIndex { get; }Property Value
Version
Gets the version number of the list.
public int Version { get; }Property Value
Methods
Add(TRow)
Adds an item to the ICollection<T>.
public void Add(TRow item)Parameters
- itemTRow
- The object to add to the ICollection<T>. 
Exceptions
- NotSupportedException
- The ICollection<T> is read-only. 
Clear()
Removes all items from the ICollection<T>.
public void Clear()Exceptions
- NotSupportedException
- The ICollection<T> is read-only. 
Contains(TRow)
Determines whether the ICollection<T> contains a specific value.
public bool Contains(TRow item)Parameters
- itemTRow
- The object to locate in the ICollection<T>. 
Returns
- bool
- true if - itemis found in the ICollection<T>; otherwise, false.
CopyTo(TRow[], int)
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
public void CopyTo(TRow[] array, int arrayIndex)Parameters
- arrayTRow[]
- The one-dimensional Array that is the destination of the elements copied from ICollection<T>. The Array must have zero-based indexing. 
- arrayIndexint
- The zero-based index in - arrayat which copying begins.
Exceptions
- ArgumentNullException
- arrayis null.
- ArgumentOutOfRangeException
- arrayIndexis less than 0.
- ArgumentException
- The number of elements in the source ICollection<T> is greater than the available space from - arrayIndexto the end of the destination- array.
GetByRid(uint)
Gets the contents of a row by its row identifier.
public TRow GetByRid(uint rid)Parameters
- riduint
- The row identifier. 
Returns
- TRow
- The row. 
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<TRow> GetEnumerator()Returns
- IEnumerator<TRow>
- An enumerator that can be used to iterate through the collection. 
GetPhysicalSize()
Computes the number of bytes that the structure contains.
public override uint GetPhysicalSize()Returns
- uint
- The number of bytes. 
GetRowBounds(uint)
Calculates the offset range of a row within the table.
public OffsetRange GetRowBounds(uint rid)Parameters
- riduint
- The identifier of the row to get the bounds of. 
Returns
- OffsetRange
- The bounds. 
Remarks
This method does not do any verification on whether rid is a valid row in the table.
GetRowRef(uint)
Gets a mutable reference to a row within the table.
public ref TRow GetRowRef(uint rid)Parameters
- riduint
- The RID of the row to obtain a reference for. 
Returns
- TRow
- The row reference. 
GetRowRef(uint, out int)
Gets a mutable reference to a row within the table.
public ref TRow GetRowRef(uint rid, out int version)Parameters
- riduint
- The RID of the row to obtain a reference for. 
- versionint
- The version of the underlying buffer upon obtaining the reference. 
Returns
- TRow
- The row reference. 
GetRows()
Obtains all rows in the metadata table.
protected virtual RefList<TRow> GetRows()Returns
- RefList<TRow>
- The rows. 
Remarks
This method is called upon initialization of the Rows property.
Insert(int, TRow)
Inserts a row in the table at the provided index.
public void Insert(int index, TRow item)Parameters
- indexint
- The index to insert at. 
- itemTRow
- The row to insert. 
Remove(TRow)
Removes the first occurrence of a specific object from the ICollection<T>.
public bool Remove(TRow item)Parameters
- itemTRow
- The object to remove from the ICollection<T>. 
Returns
- bool
- true if - itemwas successfully removed from the ICollection<T>; otherwise, false. This method also returns false if- itemis not found in the original ICollection<T>.
Exceptions
- NotSupportedException
- The ICollection<T> is read-only. 
SetByRid(uint, TRow)
Sets the contents of a row by its row identifier.
public void SetByRid(uint rid, TRow row)Parameters
- riduint
- The row identifier. 
- rowTRow
- The new contents of the row. 
TryGetByRid(uint, out TRow)
Attempts to get the contents of a row by its row identifier.
public bool TryGetByRid(uint rid, out TRow row)Parameters
- riduint
- The row identifier. 
- rowTRow
- When successful, the read row. 
Returns
- bool
- trueif the RID existed an the row was obtained successfully,- falseotherwise.
TryGetCell(uint, int, out uint)
Attempts to get the contents of a cell in the table by its row identifier and column index.
public bool TryGetCell(uint rid, int column, out uint value)Parameters
- riduint
- The row identifier. 
- columnint
- The column index. 
- valueuint
- When successful, the contents of the cell, converted to an unsigned integer. 
Returns
- bool
- trueif the cell existed and was obtained successfully,- falseotherwise.
TryGetRidByKey(int, uint, out uint)
Attempts to find a row index in a table by a key. This requires the table to be sorted.
public bool TryGetRidByKey(int keyColumnIndex, uint key, out uint rid)Parameters
- keyColumnIndexint
- The column number to get the key from. 
- keyuint
- The key to search. 
- riduint
- When this functions returns - true, this parameter contains the RID of the row that contains the given key.
Returns
- bool
- trueif the row was found,- falseotherwise.
TryGetRowByKey(int, uint, out TRow)
Gets a single row in a table by a key. This requires the table to be sorted.
public bool TryGetRowByKey(int keyColumnIndex, uint key, out TRow row)Parameters
- keyColumnIndexint
- The column number to get the key from. 
- keyuint
- The key to search. 
- rowTRow
- When this functions returns - true, this parameter contains the first row that contains the given key.
Returns
- bool
- trueif the row was found,- falseotherwise.
UpdateTableLayout(TableLayout)
Updates the table layout.
public virtual void UpdateTableLayout(TableLayout layout)Parameters
- layoutTableLayout
- The new table layout. 
Remarks
This method is used to update the sizes of each column, and therefore requires the new layout to have the same names and column types as the original one.
Write(BinaryStreamWriter)
Serializes the structure to an output stream.
public override void Write(BinaryStreamWriter writer)Parameters
- writerBinaryStreamWriter
- The output stream to write the data to.