-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] Standardize IEquatable<T> implementations across types overriding Equals
#16665
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
Conversation
|
Thank you, @RenderMichael for this code suggestion. The support packages contain example code that many users find helpful, but they do not necessarily represent After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||
|
Risky in terms of breaking change?.. I think so. |
|
I did my best to keep all things the same, including keeping the culture for string comparisons. All of this works exactly as before, with one change: |
|
Yes, changing implementation of Type starts to implement new interface, if some another type rely on this new interface (which is not implemented by consumers)... binary breaking change? UPD: starts to rely on this interface |
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.
Pull request overview
This PR standardizes the implementation of IEquatable<T> across .NET types that override Equals(object), aligning with best practices recommended by analyzer rules like CA1066. The changes improve type safety, enable better IntelliSense support, and establish a consistent pattern for equality comparisons throughout the codebase.
Key changes:
- Implemented
IEquatable<T>interface on 10 types (WebElement, SessionId, Cookie, InitializationScript, DesiredCapabilities, and event firing wrapper classes) - Refactored
Equals(object)methods to delegate to strongly-typedEquals(T)implementations - Improved hash code calculations with better null-handling using null-coalescing operators
- Standardized XML documentation to use
<see langword>tags for boolean literals
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| WebElement.cs | Implements IEquatable with proper delegation pattern and null handling for wrapped elements |
| SessionId.cs | Adds IEquatable with string comparison for session keys |
| ReadOnlyDesiredCapabilities.cs | Improves GetHashCode readability using null-coalescing operator |
| DesiredCapabilities.cs | Implements IEquatable and refactors equality logic for better structure |
| ILogger.cs | Updates documentation to use tags for boolean literals |
| ILogContext.cs | Updates documentation to use tags for boolean literals |
| InitializationScript.cs | Adds IEquatable comparing script ID, name, and source |
| Cookie.cs | Implements IEquatable and improves GetHashCode to include both name and value |
| EventFiringWebDriver.cs | Adds IEquatable implementations to EventFiringWebElement and EventFiringShadowRoot wrapper classes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
|
@nvborisenko Do you mean if someone did something like this? public class DerivedCookie : Cookie, IEquatable<Cookie>
{
public bool Equals(Cookie other)
{
return other is not null && other.Name == Name && other.Value == Value;
}
}If so, they would now just get a warning that Equals(Cookie) hides the base Equals(Cookie). No big deal. If you mean something else, could you provide a code sample? |
Co-authored-by: Copilot <[email protected]>
|
No, it is not binary breaking change. Existing code still invokes |
|
CI is broken and it will not give any useful results to wait for it; previous runs showed green CI. |
User description
It is considered standard practice to implement
IEquatable<T>when overridingbool Equals(object).🔄 Types of changes
PR Type
Enhancement
Description
Implement
IEquatable<T>interface across multiple typesStandardize
Equals()method implementations with proper null handlingImprove hash code calculations for better equality semantics
Update XML documentation to use standard
<see langword>tagsDiagram Walkthrough
File Walkthrough
10 files
Add IEquatable implementations to event firing elementsImplement IEquatable with ordinal comparisonAdd IEquatable with ordinal string comparisonImplement IEquatable with ordinal comparisonImplement IEquatable with improved hash codeAdd IEquatable implementationImplement IEquatable with refactored logicImprove hash code calculation with null-coalescing operatorAdd IEquatable implementationImplement IEquatable with proper delegation2 files
Update documentation tags to use langword formatUpdate documentation tags to use langword format