-4

Default implementation in interface is still trying to force me to implement that member; I'm currently using .Net 7.0 on VS 2022

my analysis to the issue is that it only happens when this default implementation is to satisfy the implementation of another interface to the said interface, it just doesn't make sense why they would ignore that because in my case it makes a perfect sense to have the default implementation of IEquatable<T> of T in T itself!

  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include your source code as a working [mcve], which can be tested by others. [Please do not upload images of code/errors when asking a question.](https://meta.stackoverflow.com/q/285551) – Progman Aug 27 '22 at 11:56
  • trying to explain the error without showing such an image would've been way more confusing than it is and than it has to be, rules are made to make things better, not to downvote posts for no reason when your rules serves no good purpose here. good job pushing people out of the forum – User45842185 Aug 27 '22 at 11:58
  • 1
    Progman was asking you to include your code and any corresponding error as text. – ProgrammingLlama Aug 27 '22 at 12:32

2 Answers2

1

You're almost there:

bool IEquatable<IEdiPart>.Equals(IEdiPart other) =>
    this.UniqueId == other?.UniqueId;
Ivan
  • 343
  • 2
  • 7
0

When writing new bool Equals(IEdiPart other) => ... you enforce your method to be a really new one (which happens to have the same name as the one from IEquatable<IEdiPart>). But even without the new, the problem persists.

Instead, you can make it explicit that your default method implements the method declared in the interface:

bool IEquatable<IFoo>.Equals(IFoo? other) =>
    this.UniqueId == other?.UniqueId;
Hero Wanders
  • 3,237
  • 1
  • 10
  • 14