diff --git a/Shared/General/ValueRange.cs b/Shared/General/ValueRange.cs index 8b31d57..42d1ed7 100644 --- a/Shared/General/ValueRange.cs +++ b/Shared/General/ValueRange.cs @@ -7,7 +7,7 @@ public sealed class ValueRange( T? lower, T? upper, bool isLowerInclusive, bool isUpperInclusive, bool hasLower, bool hasUpper -) where T : notnull, IComparable { +) : IEquatable?> where T : notnull, IComparable { #region 基础字段 @@ -186,4 +186,33 @@ public sealed class ValueRange( return new(lower, upper, isLowerInclusive, isUpperInclusive, anyHasLower, anyHasUpper); } + #region 相等判断(自动生成) + + public override bool Equals(object? obj) => Equals(obj as ValueRange); + public bool Equals(ValueRange? other) { + return other is not null&& + EqualityComparer.Default.Equals(Lower, other.Lower)&& + EqualityComparer.Default.Equals(Upper, other.Upper)&& + HasLower==other.HasLower&& + HasUpper==other.HasUpper&& + IsLowerInclusive==other.IsLowerInclusive&& + IsUpperInclusive==other.IsUpperInclusive; + } + public override int GetHashCode() { + int hashCode = 169504101; + hashCode=hashCode*-1521134295+EqualityComparer.Default.GetHashCode(Lower); + hashCode=hashCode*-1521134295+EqualityComparer.Default.GetHashCode(Upper); + hashCode=hashCode*-1521134295+HasLower.GetHashCode(); + hashCode=hashCode*-1521134295+HasUpper.GetHashCode(); + hashCode=hashCode*-1521134295+IsLowerInclusive.GetHashCode(); + hashCode=hashCode*-1521134295+IsUpperInclusive.GetHashCode(); + return hashCode; + } +#pragma warning disable CS8604 // 引用类型参数可能为 null。 + public static bool operator ==(ValueRange? left, ValueRange? right) => EqualityComparer>.Default.Equals(left, right); +#pragma warning restore CS8604 // 引用类型参数可能为 null。 + public static bool operator !=(ValueRange? left, ValueRange? right) => !(left==right); + + #endregion + } \ No newline at end of file