error CS0111: Type 'SomeType' already defines a member called 'Equals' with the same parameter types
jlaanstra opened this issue · 7 comments
Describe the bug
CsWinRT generates duplicate Equals methods if the underlying type in the WInMD already has an Equals() method with itself as the type parameter
To Reproduce
Create a C++WinRT component with a type that has an Equals method with itself as the equator. For example:
runtimeclass SomeType
{
SomeType();
Boolean Equals(SomeType someType);
};
Pass the WinMD to CsWinRT.
Expected behavior
No error.
Version Info
CsWinRT 1.2.6
We should investigate the built-in support behavior in .NET Native/.NET Core to see what they do
With existing built-in .NET support for WinRT, default behavior for ToString, Equals(Object), and GetHashCode methods is provided for C# WinRT components. According to these docs, Windows Runtime classes that are written in C# or Visual Basic can override the Equals(Object) method overload.
@Scottj1s - is it possible to define/override the Equals method from a C++/WinRT component that is projected into C#/.NET 5?
Looking into the existing .NET Native support:
If we have a C++/WinRT component with the following definition:
runtimeclass Class
{
Class();
Boolean Equals(Class c);
}
Consuming this component from a .NET Native (UWP) C# application, I see two Equals methods (overloaded):
public bool Equals(Class c); // in my RuntimeComponent
public virtual bool Equals(Object obj); // in System.Runtime - this method also appears if I don't define Equals in my C++/WinRT component
CsWinRT should ensure the IEquatable pattern of 5 methods is enforced, picking up any methods that the runtime component implements.
I just ran into this problem 😭.
Same problem here.
We have an old component in C++/CX which overrides Equals and when migrating to C++/WinRT got the same issue.