Skip to content

Commit

Permalink
Add IEquatable<TRow> to metadata row structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Dec 1, 2024
1 parent b7f67d0 commit aaf4d6e
Show file tree
Hide file tree
Showing 53 changed files with 634 additions and 312 deletions.
28 changes: 14 additions & 14 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyDefinitionRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly definition metadata table.
/// </summary>
public struct AssemblyDefinitionRow : IMetadataRow
public struct AssemblyDefinitionRow : IMetadataRow, IEquatable<AssemblyDefinitionRow>
{
/// <summary>
/// Reads a single assembly definition row from an input stream.
Expand Down Expand Up @@ -181,11 +181,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(Culture, (IndexSize) layout.Columns[8].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided assembly definition row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(AssemblyDefinitionRow other)
{
return HashAlgorithm == other.HashAlgorithm
Expand Down Expand Up @@ -230,14 +226,18 @@ public override string ToString()
}

/// <inheritdoc />
public IEnumerator<uint> GetEnumerator()
{
return new MetadataRowColumnEnumerator(this);
}
public IEnumerator<uint> GetEnumerator() => new MetadataRowColumnEnumerator(this);

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyDefinitionRow left, AssemblyDefinitionRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyDefinitionRow left, AssemblyDefinitionRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyOSRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly operating system metadata table.
/// </summary>
public struct AssemblyOSRow : IMetadataRow
public struct AssemblyOSRow : IMetadataRow, IEquatable<AssemblyOSRow>
{
/// <summary>
/// Reads a single assembly operating system row from an input stream.
Expand Down Expand Up @@ -87,11 +87,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteUInt32(MinorVersion);
}

/// <summary>
/// Determines whether this row is considered equal to the provided assembly operating system row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(AssemblyOSRow other)
{
return PlatformId == other.PlatformId
Expand Down Expand Up @@ -130,5 +126,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyOSRow left, AssemblyOSRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyOSRow left, AssemblyOSRow right) => !(left == right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly processor metadata table.
/// </summary>
public struct AssemblyProcessorRow : IMetadataRow
public struct AssemblyProcessorRow : IMetadataRow, IEquatable<AssemblyProcessorRow>
{
/// <summary>
/// Reads a single assembly processor row from an input stream.
Expand Down Expand Up @@ -96,5 +96,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyProcessorRow left, AssemblyProcessorRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyProcessorRow left, AssemblyProcessorRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyRefOSRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly reference operating system metadata table.
/// </summary>
public struct AssemblyRefOSRow : IMetadataRow
public struct AssemblyRefOSRow : IMetadataRow, IEquatable<AssemblyRefOSRow>
{
/// <summary>
/// Reads a single assembly reference operating system row from an input stream.
Expand Down Expand Up @@ -103,11 +103,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(AssemblyReference, (IndexSize) layout.Columns[3].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided assembly operating system row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(AssemblyRefOSRow other)
{
return PlatformId == other.PlatformId
Expand Down Expand Up @@ -151,5 +147,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyRefOSRow left, AssemblyRefOSRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyRefOSRow left, AssemblyRefOSRow right) => !(left == right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly reference processor metadata table.
/// </summary>
public struct AssemblyRefProcessorRow : IMetadataRow
public struct AssemblyRefProcessorRow : IMetadataRow, IEquatable<AssemblyRefProcessorRow>
{
/// <summary>
/// Reads a single assembly reference processor row from an input stream.
Expand Down Expand Up @@ -74,11 +74,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(AssemblyReference, (IndexSize) layout.Columns[1].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided assembly processor row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(AssemblyRefProcessorRow other)
{
return ProcessorId == other.ProcessorId && AssemblyReference == other.AssemblyReference;
Expand Down Expand Up @@ -115,5 +111,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyRefProcessorRow left, AssemblyRefProcessorRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyRefProcessorRow left, AssemblyRefProcessorRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/AssemblyReferenceRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the assembly definition metadata table.
/// </summary>
public struct AssemblyReferenceRow : IMetadataRow
public struct AssemblyReferenceRow : IMetadataRow, IEquatable<AssemblyReferenceRow>
{
/// <summary>
/// Reads a single assembly definition row from an input stream.
Expand Down Expand Up @@ -180,11 +180,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(HashValue, (IndexSize) layout.Columns[8].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided assembly reference row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(AssemblyReferenceRow other)
{
return MajorVersion == other.MajorVersion
Expand Down Expand Up @@ -238,5 +234,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(AssemblyReferenceRow left, AssemblyReferenceRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(AssemblyReferenceRow left, AssemblyReferenceRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/ClassLayoutRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the class layout metadata table.
/// </summary>
public struct ClassLayoutRow : IMetadataRow
public struct ClassLayoutRow : IMetadataRow, IEquatable<ClassLayoutRow>
{
/// <summary>
/// Reads a single class layout row from an input stream.
Expand Down Expand Up @@ -90,11 +90,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(Parent, (IndexSize) layout.Columns[2].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided class layout row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(ClassLayoutRow other)
{
return PackingSize == other.PackingSize && ClassSize == other.ClassSize && Parent == other.Parent;
Expand Down Expand Up @@ -134,5 +130,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(ClassLayoutRow left, ClassLayoutRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(ClassLayoutRow left, ClassLayoutRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/ConstantRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the constants metadata table.
/// </summary>
public struct ConstantRow : IMetadataRow
public struct ConstantRow : IMetadataRow, IEquatable<ConstantRow>
{
/// <summary>
/// Reads a single constant row from an input stream.
Expand Down Expand Up @@ -110,11 +110,7 @@ public uint Value
set;
}

/// <summary>
/// Determines whether this row is considered equal to the provided constant row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(ConstantRow other)
{
return Type == other.Type
Expand Down Expand Up @@ -167,5 +163,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(ConstantRow left, ConstantRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(ConstantRow left, ConstantRow right) => !(left == right);
}
}
18 changes: 12 additions & 6 deletions src/AsmResolver.PE/DotNet/Metadata/Tables/CustomAttributeRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the custom attribute metadata table.
/// </summary>
public struct CustomAttributeRow : IMetadataRow
public struct CustomAttributeRow : IMetadataRow, IEquatable<CustomAttributeRow>
{
/// <summary>
/// Reads a single custom attribute row from an input stream.
Expand Down Expand Up @@ -84,11 +84,7 @@ public uint Value
set;
}

/// <summary>
/// Determines whether this row is considered equal to the provided custom attribute row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(CustomAttributeRow other)
{
return Parent == other.Parent
Expand Down Expand Up @@ -132,5 +128,15 @@ IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(CustomAttributeRow left, CustomAttributeRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(CustomAttributeRow left, CustomAttributeRow right) => !(left == right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AsmResolver.PE.DotNet.Metadata.Tables
/// <summary>
/// Represents a single row in the Portable PDB custom debug information metadata table.
/// </summary>
public struct CustomDebugInformationRow : IMetadataRow
public struct CustomDebugInformationRow : IMetadataRow, IEquatable<CustomDebugInformationRow>
{
/// <summary>
/// Creates a new row for the Portable PDB custom debug information metadata table.
Expand Down Expand Up @@ -93,11 +93,7 @@ public void Write(BinaryStreamWriter writer, TableLayout layout)
writer.WriteIndex(Value, (IndexSize) layout.Columns[2].Size);
}

/// <summary>
/// Determines whether this row is considered equal to the provided custom debug information row.
/// </summary>
/// <param name="other">The other row.</param>
/// <returns><c>true</c> if the rows are equal, <c>false</c> otherwise.</returns>
/// <inheritdoc />
public bool Equals(CustomDebugInformationRow other)
{
return Parent == other.Parent && Kind == other.Kind && Value == other.Value;
Expand Down Expand Up @@ -128,5 +124,15 @@ public override int GetHashCode()
public IEnumerator<uint> GetEnumerator() => new MetadataRowColumnEnumerator(this);

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

/// <summary>
/// Determines whether two rows are considered equal.
/// </summary>
public static bool operator ==(CustomDebugInformationRow left, CustomDebugInformationRow right) => left.Equals(right);

/// <summary>
/// Determines whether two rows are not considered equal.
/// </summary>
public static bool operator !=(CustomDebugInformationRow left, CustomDebugInformationRow right) => !(left == right);
}
}
Loading

0 comments on commit aaf4d6e

Please sign in to comment.