Created
January 2, 2025 13:02
-
-
Save Sl4vP0weR/f18c35dfef06932598ae5b582043fd8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MethodSignatureComparer : IEqualityComparer<ParameterInfo> | |
{ | |
public static readonly MethodSignatureComparer Default = new(); | |
public bool Match(MethodInfo signatureMethod, MethodInfo otherMethod) | |
{ | |
var signatureParameters = signatureMethod.GetParameters(); | |
var parameters = otherMethod.GetParameters(); | |
if (otherMethod.Name != signatureMethod.Name) | |
return false; | |
if (signatureParameters.Any(x => !parameters.Contains(x, Default))) | |
return false; | |
return Equals(otherMethod.ReturnParameter, signatureMethod.ReturnParameter); | |
} | |
public bool Equals(ParameterInfo? x, ParameterInfo? y) | |
{ | |
if (ReferenceEquals(x, y)) return true; | |
if (x is null) return false; | |
if (y is null) return false; | |
if (x.IsOut != y.IsOut) return false; | |
if (x.IsRetval != y.IsRetval) return false; | |
if (x.Name != y.Name) return false; | |
if (x.ParameterType != y.ParameterType) return false; | |
return true; | |
} | |
public int GetHashCode(ParameterInfo obj) => | |
HashCode.Combine(obj.IsOut, obj.IsRetval, obj.Name, obj.ParameterType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment