Let's say I have an this code:
public interface IInterface
{
// Properties...
}
internal class Realisation : IInterface, IEquatable<IInterface>
{
// Properties...
public bool Equals(IInterface other)
{
// ...
}
public override bool Equals(object obj)
{
return Equals(obj as IInterface);
}
public override int GetHashCode()
{
// ...
}
}
The purpose is to not have duplication/different version of the equality code.
I don't have access to Realisation
because the code is in a library.
If I have to call the equality comparer of IInterface
, does it make sense to call EqualityComparer<IInterface>.Default
here? Will it use the Equals(IInterface other)
implementation? Or should the equality implementation lies outside of the class? Should I provide a custom IEqualityComparer<IInterface>
?
Edit
- Added
Equals(object obj)
andGetHashCode()
overrides