Skip to content

Commit

Permalink
Add equality methods to MethodImplementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Washi1337 committed Sep 17, 2022
1 parent 67a659e commit d10cf47
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/AsmResolver.DotNet/MethodImplementation.cs
@@ -1,9 +1,11 @@
using System;

namespace AsmResolver.DotNet
{
/// <summary>
/// Defines an explicit implementation of a method defined by an interface.
/// </summary>
public readonly struct MethodImplementation
public readonly struct MethodImplementation : IEquatable<MethodImplementation>
{
/// <summary>
/// Creates a new explicit implementation of a method.
Expand Down Expand Up @@ -33,7 +35,31 @@ public MethodImplementation(IMethodDefOrRef? declaration, IMethodDefOrRef? body)
}

/// <inheritdoc />
public override string ToString() =>
$".override {Declaration} with {Body}";
public override string ToString() => $".override {Declaration} with {Body}";

/// <summary>
/// Determines whether two method implementations record are equal.
/// </summary>
/// <param name="other">The other implementation record.</param>
/// <returns><c>true</c> if they are considered equal, <c>false</c> otherwise.</returns>
public bool Equals(MethodImplementation other)
{
return Equals(Declaration, other.Declaration) && Equals(Body, other.Body);
}

/// <inheritdoc />
public override bool Equals(object? obj)
{
return obj is MethodImplementation other && Equals(other);
}

/// <inheritdoc />
public override int GetHashCode()
{
unchecked
{
return ((Declaration != null ? Declaration.GetHashCode() : 0) * 397) ^ (Body != null ? Body.GetHashCode() : 0);
}
}
}
}

0 comments on commit d10cf47

Please sign in to comment.