recorefx / RecoreFX

A simple library for a better C#
https://recorefx.github.io
MIT License
2 stars 0 forks source link

Implement `IComparable<T?>` and `IEquatable<T?>` #162

Closed brcrista closed 3 years ago

brcrista commented 4 years ago

According to the guidance at https://github.com/dotnet/runtime/blob/master/docs/coding-guidelines/api-guidelines/nullability.md#interface-implementations

IComparable<T>

IEquatable<T>

brcrista commented 3 years ago

I tested this out and it works as you'd expect. IEquatable<T> looks like:

public interface IEquatable<T>
{
    bool Equals(T? obj);
}

So, IEquatable<T?> looks exactly the same, and you can implement it without additional modifications. But, if you have a method that takes a parameter of type IEquatable<T?> and you only implement IEquatable<T>, you'll get a warning.

On the other hand, you can assign an IEquatable<T?> to an IEquatable<T> just fine.