diff --git a/src/Nito.Comparers.Core/ComparableBase.cs b/src/Nito.Comparers.Core/ComparableBase.cs index e694feb..19770e1 100644 --- a/src/Nito.Comparers.Core/ComparableBase.cs +++ b/src/Nito.Comparers.Core/ComparableBase.cs @@ -36,7 +36,7 @@ public abstract class ComparableBase : IEquatable, IComparable, IComparabl /// /// The object to compare with this instance. May be null. /// A value indicating whether this instance is equal to the specified object. - public bool Equals(T other) => ComparableImplementations.ImplementEquals(DefaultComparer, (T)this, other!); + public bool Equals([MaybeNull] T other) => ComparableImplementations.ImplementEquals(DefaultComparer, (T)this, other!); /// /// Returns a value indicating the relative order of this instance and the specified object: a negative value if this instance is less than the specified object; zero if this instance is equal to the specified object; and a positive value if this instance is greater than the specified object. @@ -50,6 +50,6 @@ public abstract class ComparableBase : IEquatable, IComparable, IComparabl /// /// The object to compare with this instance. May be null. /// A value indicating the relative order of this instance and the specified object: a negative value if this instance is less than the specified object; zero if this instance is equal to the specified object; and a positive value if this instance is greater than the specified object. - public int CompareTo(T other) => ComparableImplementations.ImplementCompareTo(DefaultComparer, (T)this, other!); + public int CompareTo([MaybeNull] T other) => ComparableImplementations.ImplementCompareTo(DefaultComparer, (T)this, other!); } } diff --git a/src/Nito.Comparers.Core/EquatableBase.cs b/src/Nito.Comparers.Core/EquatableBase.cs index 2372d1f..815c8f0 100644 --- a/src/Nito.Comparers.Core/EquatableBase.cs +++ b/src/Nito.Comparers.Core/EquatableBase.cs @@ -36,6 +36,6 @@ public abstract class EquatableBase : IEquatable where T : EquatableBase /// The object to compare with this instance. May be null. /// A value indicating whether this instance is equal to the specified object. - public bool Equals(T other) => ComparableImplementations.ImplementEquals(DefaultComparer, (T)this, other!); + public bool Equals([MaybeNull] T other) => ComparableImplementations.ImplementEquals(DefaultComparer, (T)this, other!); } } diff --git a/src/Nito.Comparers.Core/Nito.Comparers.Core.csproj b/src/Nito.Comparers.Core/Nito.Comparers.Core.csproj index 1d23391..3132bec 100644 --- a/src/Nito.Comparers.Core/Nito.Comparers.Core.csproj +++ b/src/Nito.Comparers.Core/Nito.Comparers.Core.csproj @@ -5,4 +5,10 @@ comparer;equalitycomparer;icomparable;iequatable Nito.Comparers + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/src/Nito.Comparers.Core/Util/ComparableImplementations.cs b/src/Nito.Comparers.Core/Util/ComparableImplementations.cs index 99f68e4..dc91e90 100644 --- a/src/Nito.Comparers.Core/Util/ComparableImplementations.cs +++ b/src/Nito.Comparers.Core/Util/ComparableImplementations.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Nito.Comparers.Util { @@ -77,7 +78,7 @@ public static bool ImplementEquals(System.Collections.IEqualityComparer equality /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpEquality(IEqualityComparer equalityComparer, T left, T right) + public static bool ImplementOpEquality(IEqualityComparer equalityComparer, [MaybeNull] T left, [MaybeNull] T right) { _ = equalityComparer ?? throw new ArgumentNullException(nameof(equalityComparer)); return equalityComparer.Equals(left, right); @@ -90,7 +91,7 @@ public static bool ImplementOpEquality(IEqualityComparer equalityComparer, /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpInequality(IEqualityComparer equalityComparer, T left, T right) + public static bool ImplementOpInequality(IEqualityComparer equalityComparer, [MaybeNull] T left, [MaybeNull] T right) { _ = equalityComparer ?? throw new ArgumentNullException(nameof(equalityComparer)); return !equalityComparer.Equals(left, right); @@ -103,7 +104,7 @@ public static bool ImplementOpInequality(IEqualityComparer equalityCompare /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpLessThan(IComparer comparer, T left, T right) + public static bool ImplementOpLessThan(IComparer comparer, [MaybeNull] T left, [MaybeNull] T right) { _ = comparer ?? throw new ArgumentNullException(nameof(comparer)); return comparer.Compare(left, right) < 0; @@ -116,7 +117,7 @@ public static bool ImplementOpLessThan(IComparer comparer, T left, T right /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpGreaterThan(IComparer comparer, T left, T right) + public static bool ImplementOpGreaterThan(IComparer comparer, [MaybeNull] T left, [MaybeNull] T right) { _ = comparer ?? throw new ArgumentNullException(nameof(comparer)); return comparer.Compare(left, right) > 0; @@ -129,7 +130,7 @@ public static bool ImplementOpGreaterThan(IComparer comparer, T left, T ri /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpLessThanOrEqual(IComparer comparer, T left, T right) + public static bool ImplementOpLessThanOrEqual(IComparer comparer, [MaybeNull] T left, [MaybeNull] T right) { _ = comparer ?? throw new ArgumentNullException(nameof(comparer)); return comparer.Compare(left, right) <= 0; @@ -142,7 +143,7 @@ public static bool ImplementOpLessThanOrEqual(IComparer comparer, T left, /// The comparer. May not be null. /// A value of type or null. /// A value of type or null. - public static bool ImplementOpGreaterThanOrEqual(IComparer comparer, T left, T right) + public static bool ImplementOpGreaterThanOrEqual(IComparer comparer, [MaybeNull] T left, [MaybeNull] T right) { _ = comparer ?? throw new ArgumentNullException(nameof(comparer)); return comparer.Compare(left, right) >= 0;