mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-16 11:21:08 -10:00
We need to revise our use of nullable for `IComparable<T>` and `IEquatable<T>`: - For reference types that implement `IComparable<T>`, the implementation should use `IComparable<T?>`, e.g. `String : IComparable<String?>`, so that the type can be used in methods with a `where T : IComparable<T>` constraint: `IComparable<T>`'s contravariance then allows both `T` and `T?` to work as generic type arguments. - For reference types that implement `IEquatable<T>`, we can't take advantage of such contravariance, as by design `IEquatable<T>` is invariant (it would be a breaking change to make it contravariant, and even if it wasn't doing so is of questionable design given that equality and inheritance don't mix well). Given the current language design, we have little option but to explicitly make any reference type implementations of `IEquatable<T>` be oblivious, and also make all `where T : IEquatable<T>` constraints be oblivious. Otherwise, regardless nullable annotations, a developer will get a warning for using either or both of `T`/`T?` with any given method employing such a constraint. Signed-off-by: dotnet-bot <[email protected]>
14 lines
429 B
C#
14 lines
429 B
C#
// Licensed to the .NET Foundation under one or more agreements.
|
|
// The .NET Foundation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace System
|
|
{
|
|
public interface IEquatable<T> // invariant due to questionable semantics around equality and inheritance
|
|
{
|
|
bool Equals([AllowNull] T other);
|
|
}
|
|
}
|