Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add operator overrides for public IComparable types, #683 #1056

Merged
merged 6 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lucene.Net.QueryParser/Surround/Query/SimpleTerm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Lucene.Net.Index;
using System;
using System.Text;
#pragma warning disable CS0660, CS0661 - CompareTo is deprecated, so skipping implementing equality members (lucenenet#683)
#pragma warning disable CS0660, CS0661 // CompareTo is deprecated, so skipping implementing equality members (lucenenet#683)

namespace Lucene.Net.QueryParsers.Surround.Query
{
Expand Down
14 changes: 6 additions & 8 deletions src/Lucene.Net.Suggest/Suggest/Fst/FSTCompletion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@ public int CompareTo(Completion o)
}

// LUCENENET specific - per CS0660 and CS0661, we need to override Equals and GetHashCode
public override bool Equals(object obj) => ReferenceEquals(this, obj);
// ReSharper disable once BaseObjectEqualsIsObjectEquals
// ReSharper disable once RedundantOverriddenMember
public override bool Equals(object obj) => base.Equals(obj);

public override int GetHashCode()
{
unchecked
{
return (Utf8.GetHashCode() * 397) ^ Bucket;
}
}
// ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode
// ReSharper disable once RedundantOverriddenMember
public override int GetHashCode() => base.GetHashCode();

#region Operator overrides
#nullable enable
Expand Down
19 changes: 6 additions & 13 deletions src/Lucene.Net.Suggest/Suggest/Lookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,13 @@ public int CompareTo(LookupResult o)
}

// LUCENENET specific - per CS0660 and CS0661, we need to override Equals and GetHashCode
public override bool Equals(object obj) => ReferenceEquals(this, obj);
// ReSharper disable once BaseObjectEqualsIsObjectEquals
// ReSharper disable once RedundantOverriddenMember
public override bool Equals(object obj) => base.Equals(obj);

public override int GetHashCode()
{
unchecked
paulirwin marked this conversation as resolved.
Show resolved Hide resolved
{
var hashCode = (Key != null ? Key.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (HighlightKey != null ? HighlightKey.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ Value.GetHashCode();
hashCode = (hashCode * 397) ^ (Payload != null ? Payload.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Contexts != null ? Contexts.GetHashCode() : 0);
return hashCode;
}
}
// ReSharper disable once BaseObjectGetHashCodeCallInGetHashCode
// ReSharper disable once RedundantOverriddenMember
public override int GetHashCode() => base.GetHashCode();

#region Operator overrides
// LUCENENET specific - per csharpsquid:S1210, IComparable<T> should override comparison operators
Expand Down
3 changes: 2 additions & 1 deletion src/Lucene.Net/Util/Automaton/State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ public virtual int CompareTo(State s)
// IndexOutOfRangeExceptions when using FuzzyTermsEnum.
// See GH-296.
// Overriding here to prevent CS0660 warning due to defining the == operator.
public override bool Equals(object obj) => ReferenceEquals(this, obj);
// ReSharper disable once BaseObjectEqualsIsObjectEquals
public override bool Equals(object obj) => base.Equals(obj);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
Expand Down
Loading