[dotnet] Standardize `IEquatable<T>` implementations across types overriding Equals
User description
It is considered standard practice to implement IEquatable<T> when overriding bool Equals(object).
- This gives users/IntelliSense knowledge that this type has meaningful equality.
- There are analyzer rules for this, such as CA1066.
🔄 Types of changes
- New feature (non-breaking change which adds functionality and tests!)
PR Type
Enhancement
Description
-
Implement
IEquatable<T>interface across multiple types -
Standardize
Equals()method implementations with proper null handling -
Improve hash code calculations for better equality semantics
-
Update XML documentation to use standard
<see langword>tags
Diagram Walkthrough
flowchart LR
A["Types overriding Equals"] -->|"Add IEquatable<T>"| B["Implement Equals<T>"]
B -->|"Refactor Equals<object>"| C["Delegate to Equals<T>"]
C -->|"Improve GetHashCode"| D["Consistent hash calculations"]
D -->|"Update docs"| E["Use langword tags"]
File Walkthrough
| Relevant files | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 10 files
| ||||||||||||||||||||
| Documentation |
Thank you, @RenderMichael for this code suggestion.
The support packages contain example code that many users find helpful, but they do not necessarily represent the best practices for using Selenium, and the Selenium team is not currently merging changes to them.
After reviewing the change, unless it is a critical fix or a feature that is needed for Selenium to work, we will likely close the PR.
We actively encourage people to add the wrapper and helper code that makes sense for them to their own frameworks. If you have any questions, please contact us
PR Compliance Guide 🔍
Below is a summary of compliance checks for this PR:
| Security Compliance | |
| 🟢 | No security concerns identifiedNo security vulnerabilities detected by AI analysis. Human verification advised for critical code. |
| Ticket Compliance | |
| ⚪ | 🎫 No ticket provided
|
| Codebase Duplication Compliance | |
| ⚪ | Codebase context is not definedFollow the guide to enable codebase context checks. |
| Custom Compliance | |
| 🟢 |
Generic: Comprehensive Audit TrailsObjective: To create a detailed and reliable record of critical system actions for security analysis Status: Passed
|
Generic: Meaningful Naming and Self-Documenting CodeObjective: Ensure all identifiers clearly express their purpose and intent, making code Status: Passed
| |
Generic: Robust Error Handling and Edge Case ManagementObjective: Ensure comprehensive error handling that provides meaningful context and graceful Status: Passed
| |
Generic: Secure Error HandlingObjective: To prevent the leakage of sensitive system information through error messages while Status: Passed
| |
Generic: Secure Logging PracticesObjective: To ensure logs are useful for debugging and auditing without exposing sensitive Status: Passed
| |
Generic: Security-First Input Validation and Data HandlingObjective: Ensure all data inputs are validated, sanitized, and handled securely to prevent Status: Passed
| |
| |
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Use remote call for element equalityUpdate the dotnet/src/webdriver/WebElement.cs [670-691]
Suggestion importance[1-10]: 9__ Why: The suggestion correctly points out that the PR's implementation of | High |
Improve equality check for all capabilitiesModify the dotnet/src/webdriver/Remote/DesiredCapabilities.cs [262-290]
Suggestion importance[1-10]: 8__ Why: The suggestion correctly identifies that the | Medium | |
| ||
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: Cookie.GetHashCode() now includes Value instead of just Name. I consider this a bugfix, since equality requires the same Value.
Yes, changing implementation of GetHashCode() is a bug fix.
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
@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?
No, it is not binary breaking change. Existing code still invokes Method(object) overload.
CI is broken and it will not give any useful results to wait for it; previous runs showed green CI.