-
Notifications
You must be signed in to change notification settings - Fork 641
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
Conversation
This change caught a NRE bug in MutableValue 😄 Fixed. |
Well, being that they didn't override the default behavior (which is reference equality), a direct port would be to override each and then cascade the call to the base class. But given the fact that the comparer uses BTW - I noticed that the public virtual int CompareTo(QualityQuery other)
{
try
{
// compare as ints when ids ints
int n = int.Parse(queryID, CultureInfo.InvariantCulture);
int nOther = int.Parse(other.queryID, CultureInfo.InvariantCulture);
return n - nOther;
}
catch (Exception e) when (e.IsNumberFormatException())
{
// fall back to string comparison
return queryID.CompareToOrdinal(other.queryID);
}
} The constructor could also be improved by using guard clauses on
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
We are getting some build warnings in some types where Equals(object)
and GetHashCode()
have not been implemented.
Also, since these are all on nullable types, please use #nullable enable
within the #region Operator overrides
sections and #nullable restore
prior to #endregion
. We don't necessarily have to do this on the entire file in this PR.
See the inline comments.
there is a big performance penalty for using this inside try/catch block. ok, i see it fixed. great |
Sorry, what are you referring to? |
Add operator overrides for public IComparable types
Fixes #683
Description
This is to resolve the Sonar warning about needing to override the comparison operators for any types that implement IComparable. We are only doing this here for the public types.
QualityQuery was missing Equals and GetHashCode, as well as had some possible NullReferenceExceptions, so those have been fixed as well.