From d633b4c438de0f6b65358f4e979186067d18fdf1 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 1 Dec 2025 03:34:09 -0500 Subject: [PATCH 1/2] [dotnet] Standardize IEquatable implementations across types overriding Equals --- .../support/Events/EventFiringWebDriver.cs | 39 +++++++------- .../BiDi/BrowsingContext/BrowsingContext.cs | 13 +++-- .../src/webdriver/BiDi/Network/Collector.cs | 13 +++-- .../src/webdriver/BiDi/Network/Intercept.cs | 13 +++-- dotnet/src/webdriver/Cookie.cs | 52 ++++++++++++------- dotnet/src/webdriver/InitializationScript.cs | 14 ++++- .../webdriver/Internal/Logging/ILogContext.cs | 2 +- .../src/webdriver/Internal/Logging/ILogger.cs | 2 +- .../webdriver/Remote/DesiredCapabilities.cs | 37 +++++++------ .../Remote/ReadOnlyDesiredCapabilities.cs | 6 +-- dotnet/src/webdriver/SessionId.cs | 14 ++++- dotnet/src/webdriver/WebElement.cs | 24 +++++---- 12 files changed, 140 insertions(+), 89 deletions(-) diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index 974843dbce1e4..938acf6162206 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -1322,7 +1322,7 @@ public TimeSpan PageLoad /// /// EventFiringWebElement allows you to have access to specific items that are found on the page /// - private class EventFiringWebElement : ITakesScreenshot, IWebElement, IWrapsElement, IWrapsDriver + private class EventFiringWebElement : ITakesScreenshot, IWebElement, IWrapsElement, IWrapsDriver, IEquatable { private readonly EventFiringWebDriver parentDriver; @@ -1760,18 +1760,8 @@ public Screenshot GetScreenshot() return screenshotDriver.GetScreenshot(); } - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare to the current . - /// if the specified is equal to the current ; otherwise, . - public override bool Equals(object obj) + public bool Equals(IWebElement? other) { - if (obj is not IWebElement other) - { - return false; - } - if (other is IWrapsElement otherWrapper) { other = otherWrapper.WrappedElement; @@ -1780,6 +1770,16 @@ public override bool Equals(object obj) return WrappedElement.Equals(other); } + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare to the current . + /// if the specified is equal to the current ; otherwise, . + public override bool Equals(object? obj) + { + return Equals(obj as IWebElement); + } + /// /// Return the hash code for this . /// @@ -1793,7 +1793,7 @@ public override int GetHashCode() /// /// EventFiringShadowElement allows you to have access to specific shadow elements /// - private class EventFiringShadowRoot : ISearchContext, IWrapsDriver + private class EventFiringShadowRoot : ISearchContext, IWrapsDriver, IEquatable { private readonly EventFiringWebDriver parentDriver; @@ -1871,7 +1871,11 @@ public ReadOnlyCollection FindElements(By by) this.parentDriver.OnException(new WebDriverExceptionEventArgs(this.parentDriver, ex)); throw; } + } + public bool Equals(ISearchContext? other) + { + return WrappedSearchContext.Equals(other); } /// @@ -1879,14 +1883,9 @@ public ReadOnlyCollection FindElements(By by) /// /// The to compare to the current . /// if the specified is equal to the current ; otherwise, . - public override bool Equals(object obj) + public override bool Equals(object? obj) { - if (obj is not ISearchContext other) - { - return false; - } - - return WrappedSearchContext.Equals(other); + return Equals(obj as ISearchContext); } /// diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs index add2a12b9c865..1c0b6c2eca669 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs @@ -23,7 +23,7 @@ namespace OpenQA.Selenium.BiDi.BrowsingContext; -public sealed class BrowsingContext +public sealed class BrowsingContext : IEquatable { internal BrowsingContext(BiDi bidi, string id) { @@ -223,15 +223,18 @@ public Task OnNavigationCommittedAsync(Func return BiDi.BrowsingContext.OnNavigationCommittedAsync(handler, options.WithContext(this)); } - public override bool Equals(object? obj) + public bool Equals(BrowsingContext? other) { - if (obj is BrowsingContext browsingContextObj) return browsingContextObj.Id == Id; + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + } - return false; + public override bool Equals(object? obj) + { + return Equals(obj as BrowsingContext); } public override int GetHashCode() { - return Id.GetHashCode(); + return StringComparer.Ordinal.GetHashCode(Id); } } diff --git a/dotnet/src/webdriver/BiDi/Network/Collector.cs b/dotnet/src/webdriver/BiDi/Network/Collector.cs index 0a1f56a5064a5..ddb9f7b15d9ee 100644 --- a/dotnet/src/webdriver/BiDi/Network/Collector.cs +++ b/dotnet/src/webdriver/BiDi/Network/Collector.cs @@ -22,7 +22,7 @@ namespace OpenQA.Selenium.BiDi.Network; -public sealed class Collector : IAsyncDisposable +public sealed class Collector : IEquatable, IAsyncDisposable { private readonly BiDi _bidi; @@ -44,15 +44,18 @@ public async ValueTask DisposeAsync() await RemoveAsync(); } - public override bool Equals(object? obj) + public bool Equals(Collector? other) { - if (obj is Collector collectortObj) return collectortObj.Id == Id; + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + } - return false; + public override bool Equals(object? obj) + { + return Equals(obj as Collector); } public override int GetHashCode() { - return Id.GetHashCode(); + return StringComparer.Ordinal.GetHashCode(Id); } } diff --git a/dotnet/src/webdriver/BiDi/Network/Intercept.cs b/dotnet/src/webdriver/BiDi/Network/Intercept.cs index c266f791efaa3..1bb196163131e 100644 --- a/dotnet/src/webdriver/BiDi/Network/Intercept.cs +++ b/dotnet/src/webdriver/BiDi/Network/Intercept.cs @@ -24,7 +24,7 @@ namespace OpenQA.Selenium.BiDi.Network; -public sealed class Intercept : IAsyncDisposable +public sealed class Intercept : IEquatable, IAsyncDisposable { private readonly BiDi _bidi; @@ -110,15 +110,18 @@ public async ValueTask DisposeAsync() await RemoveAsync(); } - public override bool Equals(object? obj) + public bool Equals(Intercept? other) { - if (obj is Intercept interceptObj) return interceptObj.Id == Id; + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + } - return false; + public override bool Equals(object? obj) + { + return Equals(obj as Intercept); } public override int GetHashCode() { - return Id.GetHashCode(); + return StringComparer.Ordinal.GetHashCode(Id); } } diff --git a/dotnet/src/webdriver/Cookie.cs b/dotnet/src/webdriver/Cookie.cs index 292757bf7652f..dfc294e5c5eaf 100644 --- a/dotnet/src/webdriver/Cookie.cs +++ b/dotnet/src/webdriver/Cookie.cs @@ -30,7 +30,7 @@ namespace OpenQA.Selenium; /// Represents a cookie in the browser. /// [Serializable] -public class Cookie +public class Cookie : IEquatable { private readonly string cookieName; private readonly string cookieValue; @@ -319,6 +319,28 @@ public override string ToString() + "; isHttpOnly= " + this.isHttpOnly + "; secure= " + this.secure + (string.IsNullOrEmpty(this.sameSite) ? string.Empty : "; sameSite=" + this.sameSite); } + /// + /// Indicates whether the current is equal to another . + /// + /// A to compare with this . + /// if the current is equal to the parameter; otherwise, . + /// Two cookies are equal if the and match. + public bool Equals(Cookie? other) + { + if (other is null) + { + return false; + } + + if (ReferenceEquals(this, other)) + { + return true; + } + + return string.Equals(this.cookieName, other.cookieName) + && string.Equals(this.cookieValue, other.cookieValue); + } + /// /// Determines whether the specified Object is equal /// to the current Object. @@ -330,32 +352,22 @@ public override string ToString() /// . public override bool Equals(object? obj) { - // Two cookies are equal if the name and value match - if (this == obj) - { - return true; - } - - if (obj is not Cookie cookie) - { - return false; - } - - if (!this.cookieName.Equals(cookie.cookieName)) - { - return false; - } - - return string.Equals(this.cookieValue, cookie.cookieValue); + return Equals(obj as Cookie); } /// /// Serves as a hash function for a particular type. /// - /// A hash code for the current Object. + /// A hash code for the current , based on the and . public override int GetHashCode() { - return this.cookieName.GetHashCode(); + unchecked + { + int hash = 17; + hash = hash * 23 + this.cookieName.GetHashCode(); + hash = hash * 23 + this.cookieValue?.GetHashCode() ?? 0; + return hash; + } } private static string? StripPort(string? domain) diff --git a/dotnet/src/webdriver/InitializationScript.cs b/dotnet/src/webdriver/InitializationScript.cs index 6cf16079c68ac..f102503920b0b 100644 --- a/dotnet/src/webdriver/InitializationScript.cs +++ b/dotnet/src/webdriver/InitializationScript.cs @@ -27,7 +27,7 @@ namespace OpenQA.Selenium; /// /// Represents a JavaScript script that is loaded and run on every document load. /// -public class InitializationScript +public class InitializationScript : IEquatable { internal InitializationScript(string scriptId, string scriptName, string scriptSource) { @@ -52,6 +52,16 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS [StringSyntax(StringSyntaxConstants.JavaScript)] public string ScriptSource { get; } + /// + /// Indicates whether the current is equal to another of the same type. + /// + /// An to compare with this . + /// if the current is equal to the parameter; otherwise, . + public bool Equals(InitializationScript? other) + { + return other is not null && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource; + } + /// /// Indicates whether the current is equal to another of the same type. /// @@ -59,7 +69,7 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS /// if the current is equal to the other parameter; otherwise, . public override bool Equals(object? obj) { - return obj is InitializationScript other && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource; + return Equals(obj as InitializationScript); } /// diff --git a/dotnet/src/webdriver/Internal/Logging/ILogContext.cs b/dotnet/src/webdriver/Internal/Logging/ILogContext.cs index 24b90382ae7e7..38b6cbb399773 100644 --- a/dotnet/src/webdriver/Internal/Logging/ILogContext.cs +++ b/dotnet/src/webdriver/Internal/Logging/ILogContext.cs @@ -58,7 +58,7 @@ public interface ILogContext : IDisposable /// /// The specified logger instance to be checked. /// The specified log event level to be checked. - /// true if log messages emitting is enabled for the specified logger and log event level, otherwise false. + /// if log messages emitting is enabled for the specified logger and log event level, otherwise . internal bool IsEnabled(ILogger logger, LogEventLevel level); /// diff --git a/dotnet/src/webdriver/Internal/Logging/ILogger.cs b/dotnet/src/webdriver/Internal/Logging/ILogger.cs index c049a31cc820e..6a0b3de5a5a09 100644 --- a/dotnet/src/webdriver/Internal/Logging/ILogger.cs +++ b/dotnet/src/webdriver/Internal/Logging/ILogger.cs @@ -70,6 +70,6 @@ internal interface ILogger /// Checks whether logs emitting is enabled for this logger and a log event level. /// /// The specified log event level to be checked. - /// true if log messages emitting is enabled for the specified log event level, otherwise false. + /// if log messages emitting is enabled for the specified log event level, otherwise . bool IsEnabled(LogEventLevel level); } diff --git a/dotnet/src/webdriver/Remote/DesiredCapabilities.cs b/dotnet/src/webdriver/Remote/DesiredCapabilities.cs index e8990d39028c0..0830ec5b35f86 100644 --- a/dotnet/src/webdriver/Remote/DesiredCapabilities.cs +++ b/dotnet/src/webdriver/Remote/DesiredCapabilities.cs @@ -28,7 +28,7 @@ namespace OpenQA.Selenium.Remote; /// /// Internal class to specify the requested capabilities of the browser for . /// -internal class DesiredCapabilities : IWritableCapabilities, IHasCapabilitiesDictionary +internal class DesiredCapabilities : IWritableCapabilities, IHasCapabilitiesDictionary, IEquatable { private readonly Dictionary capabilities = new Dictionary(); @@ -229,9 +229,9 @@ public void SetCapability(string capability, object capabilityValue) public override int GetHashCode() { int result; - result = this.BrowserName != null ? this.BrowserName.GetHashCode() : 0; - result = (31 * result) + (this.Version != null ? this.Version.GetHashCode() : 0); - result = (31 * result) + (this.Platform != null ? this.Platform.GetHashCode() : 0); + result = this.BrowserName?.GetHashCode() ?? 0; + result = (31 * result) + (this.Version?.GetHashCode() ?? 0); + result = (31 * result) + (this.Platform?.GetHashCode() ?? 0); return result; } @@ -244,24 +244,19 @@ public override string ToString() return string.Format(CultureInfo.InvariantCulture, "Capabilities [BrowserName={0}, Platform={1}, Version={2}]", this.BrowserName, this.Platform.PlatformType.ToString(), this.Version); } - /// - /// Compare two DesiredCapabilities and will return either true or false - /// - /// DesiredCapabilities you wish to compare - /// true if they are the same or false if they are not - public override bool Equals(object? obj) + public bool Equals(DesiredCapabilities? other) { - if (this == obj) + if (other is null) { - return true; + return false; } - if (obj is not DesiredCapabilities other) + if (ReferenceEquals(this, other)) { - return false; + return true; } - if (this.BrowserName != null ? this.BrowserName != other.BrowserName : other.BrowserName != null) + if (this.BrowserName != other.BrowserName) { return false; } @@ -271,7 +266,7 @@ public override bool Equals(object? obj) return false; } - if (this.Version != null ? this.Version != other.Version : other.Version != null) + if (this.Version != other.Version) { return false; } @@ -279,6 +274,16 @@ public override bool Equals(object? obj) return true; } + /// + /// Compare two DesiredCapabilities and will return either true or false + /// + /// DesiredCapabilities you wish to compare + /// true if they are the same or false if they are not + public override bool Equals(object? obj) + { + return Equals(obj as DesiredCapabilities); + } + /// /// Returns a read-only version of this capabilities object. /// diff --git a/dotnet/src/webdriver/Remote/ReadOnlyDesiredCapabilities.cs b/dotnet/src/webdriver/Remote/ReadOnlyDesiredCapabilities.cs index 40db2fb515b83..cf8e574a2e435 100644 --- a/dotnet/src/webdriver/Remote/ReadOnlyDesiredCapabilities.cs +++ b/dotnet/src/webdriver/Remote/ReadOnlyDesiredCapabilities.cs @@ -178,9 +178,9 @@ public IDictionary ToDictionary() public override int GetHashCode() { int result; - result = this.BrowserName != null ? this.BrowserName.GetHashCode() : 0; - result = (31 * result) + (this.Version != null ? this.Version.GetHashCode() : 0); - result = (31 * result) + (this.Platform != null ? this.Platform.GetHashCode() : 0); + result = this.BrowserName?.GetHashCode() ?? 0; + result = (31 * result) + (this.Version?.GetHashCode() ?? 0); + result = (31 * result) + (this.Platform?.GetHashCode() ?? 0); return result; } diff --git a/dotnet/src/webdriver/SessionId.cs b/dotnet/src/webdriver/SessionId.cs index dc94a67823fc5..3428e4e25da22 100644 --- a/dotnet/src/webdriver/SessionId.cs +++ b/dotnet/src/webdriver/SessionId.cs @@ -24,7 +24,7 @@ namespace OpenQA.Selenium; /// /// Provides a mechanism for maintaining a session for a test /// -public class SessionId +public class SessionId : IEquatable { private readonly string sessionOpaqueKey; @@ -56,6 +56,16 @@ public override int GetHashCode() return this.sessionOpaqueKey.GetHashCode(); } + /// + /// Indicates whether the current session ID value is the same as . + /// + /// The session to compare to. + /// if the values are equal; otherwise, . + public bool Equals(SessionId? other) + { + return other is not null && string.Equals(this.sessionOpaqueKey, other.sessionOpaqueKey); + } + /// /// Indicates whether the current session ID value is the same as . /// @@ -63,6 +73,6 @@ public override int GetHashCode() /// if the values are equal; otherwise, . public override bool Equals(object? obj) { - return obj is SessionId otherSession && this.sessionOpaqueKey.Equals(otherSession.sessionOpaqueKey); + return Equals(obj as SessionId); } } diff --git a/dotnet/src/webdriver/WebElement.cs b/dotnet/src/webdriver/WebElement.cs index f54f510c701a1..144c90f4d2401 100644 --- a/dotnet/src/webdriver/WebElement.cs +++ b/dotnet/src/webdriver/WebElement.cs @@ -33,7 +33,7 @@ namespace OpenQA.Selenium; /// /// A base class representing an HTML element on a page. /// -public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference +public class WebElement : IWebElement, IFindsElement, IWrapsDriver, ILocatable, ITakesScreenshot, IWebDriverObjectReference, IEquatable { /// /// The property name that represents a web element in the wire protocol. @@ -652,18 +652,24 @@ public override int GetHashCode() } /// - /// Compares if two elements are equal + /// Indicates whether the current is equal to another object. /// - /// Object to compare against - /// A boolean if it is equal or not + /// An object to compare with this . + /// if the current is equal to the other parameter; otherwise, . public override bool Equals(object? obj) { - if (obj is not IWebElement other) - { - return false; - } + return Equals(obj as IWebElement); + } - if (obj is IWrapsElement objAsWrapsElement) + /// + /// Indicates whether the current is equal to another . + /// + /// An to compare with this . + /// if the current is equal to the parameter; otherwise, . + /// This method only returns if is or wraps a . + public bool Equals(IWebElement? other) + { + if (other is IWrapsElement objAsWrapsElement) { other = objAsWrapsElement.WrappedElement; } From 19a9bc5448306ac2d6758e57948042764f3976a3 Mon Sep 17 00:00:00 2001 From: Michael Render Date: Mon, 1 Dec 2025 03:46:10 -0500 Subject: [PATCH 2/2] [dotnet] Minimize unnecessary diffs by reordering `Equals` methods --- .../support/Events/EventFiringWebDriver.cs | 42 ++++++++++++------- .../BiDi/BrowsingContext/BrowsingContext.cs | 8 ++-- .../src/webdriver/BiDi/Network/Collector.cs | 8 ++-- .../src/webdriver/BiDi/Network/Intercept.cs | 8 ++-- dotnet/src/webdriver/Cookie.cs | 28 ++++++------- dotnet/src/webdriver/InitializationScript.cs | 16 +++---- .../webdriver/Remote/DesiredCapabilities.cs | 25 ++++++----- dotnet/src/webdriver/SessionId.cs | 16 +++---- 8 files changed, 83 insertions(+), 68 deletions(-) diff --git a/dotnet/src/support/Events/EventFiringWebDriver.cs b/dotnet/src/support/Events/EventFiringWebDriver.cs index 938acf6162206..6ea8ebd24cc86 100644 --- a/dotnet/src/support/Events/EventFiringWebDriver.cs +++ b/dotnet/src/support/Events/EventFiringWebDriver.cs @@ -1760,6 +1760,21 @@ public Screenshot GetScreenshot() return screenshotDriver.GetScreenshot(); } + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare to the current . + /// if the current is equal to the other parameter; otherwise, . + public override bool Equals(object? obj) + { + return Equals(obj as IWebElement); + } + + /// + /// Indicates whether the current is equal to another . + /// + /// An to compare with this . + /// if the current is equal to the parameter; otherwise, . public bool Equals(IWebElement? other) { if (other is IWrapsElement otherWrapper) @@ -1770,16 +1785,6 @@ public bool Equals(IWebElement? other) return WrappedElement.Equals(other); } - /// - /// Determines whether the specified is equal to the current . - /// - /// The to compare to the current . - /// if the specified is equal to the current ; otherwise, . - public override bool Equals(object? obj) - { - return Equals(obj as IWebElement); - } - /// /// Return the hash code for this . /// @@ -1873,19 +1878,24 @@ public ReadOnlyCollection FindElements(By by) } } - public bool Equals(ISearchContext? other) + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare to the current . + /// if the current is equal to the other parameter; otherwise, . + public override bool Equals(object? obj) { - return WrappedSearchContext.Equals(other); + return Equals(obj as ISearchContext); } /// /// Determines whether the specified is equal to the current . /// - /// The to compare to the current . - /// if the specified is equal to the current ; otherwise, . - public override bool Equals(object? obj) + /// The to compare to the current . + /// if the current is equal to the parameter; otherwise, . + public bool Equals(ISearchContext? other) { - return Equals(obj as ISearchContext); + return WrappedSearchContext.Equals(other); } /// diff --git a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs index 1c0b6c2eca669..61328c73c444e 100644 --- a/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs +++ b/dotnet/src/webdriver/BiDi/BrowsingContext/BrowsingContext.cs @@ -223,14 +223,14 @@ public Task OnNavigationCommittedAsync(Func return BiDi.BrowsingContext.OnNavigationCommittedAsync(handler, options.WithContext(this)); } - public bool Equals(BrowsingContext? other) + public override bool Equals(object? obj) { - return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + return Equals(obj as BrowsingContext); } - public override bool Equals(object? obj) + public bool Equals(BrowsingContext? other) { - return Equals(obj as BrowsingContext); + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); } public override int GetHashCode() diff --git a/dotnet/src/webdriver/BiDi/Network/Collector.cs b/dotnet/src/webdriver/BiDi/Network/Collector.cs index ddb9f7b15d9ee..2f97908e505d2 100644 --- a/dotnet/src/webdriver/BiDi/Network/Collector.cs +++ b/dotnet/src/webdriver/BiDi/Network/Collector.cs @@ -44,14 +44,14 @@ public async ValueTask DisposeAsync() await RemoveAsync(); } - public bool Equals(Collector? other) + public override bool Equals(object? obj) { - return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + return Equals(obj as Collector); } - public override bool Equals(object? obj) + public bool Equals(Collector? other) { - return Equals(obj as Collector); + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); } public override int GetHashCode() diff --git a/dotnet/src/webdriver/BiDi/Network/Intercept.cs b/dotnet/src/webdriver/BiDi/Network/Intercept.cs index 1bb196163131e..d1b6ebebd4600 100644 --- a/dotnet/src/webdriver/BiDi/Network/Intercept.cs +++ b/dotnet/src/webdriver/BiDi/Network/Intercept.cs @@ -110,14 +110,14 @@ public async ValueTask DisposeAsync() await RemoveAsync(); } - public bool Equals(Intercept? other) + public override bool Equals(object? obj) { - return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); + return Equals(obj as Intercept); } - public override bool Equals(object? obj) + public bool Equals(Intercept? other) { - return Equals(obj as Intercept); + return other is not null && string.Equals(Id, other.Id, StringComparison.Ordinal); } public override int GetHashCode() diff --git a/dotnet/src/webdriver/Cookie.cs b/dotnet/src/webdriver/Cookie.cs index dfc294e5c5eaf..d625ee0e34ad6 100644 --- a/dotnet/src/webdriver/Cookie.cs +++ b/dotnet/src/webdriver/Cookie.cs @@ -319,6 +319,20 @@ public override string ToString() + "; isHttpOnly= " + this.isHttpOnly + "; secure= " + this.secure + (string.IsNullOrEmpty(this.sameSite) ? string.Empty : "; sameSite=" + this.sameSite); } + /// + /// Determines whether the specified Object is equal + /// to the current Object. + /// + /// The Object to compare with the + /// current Object. + /// if the specified Object + /// is equal to the current Object; otherwise, + /// . + public override bool Equals(object? obj) + { + return Equals(obj as Cookie); + } + /// /// Indicates whether the current is equal to another . /// @@ -341,20 +355,6 @@ public bool Equals(Cookie? other) && string.Equals(this.cookieValue, other.cookieValue); } - /// - /// Determines whether the specified Object is equal - /// to the current Object. - /// - /// The Object to compare with the - /// current Object. - /// if the specified Object - /// is equal to the current Object; otherwise, - /// . - public override bool Equals(object? obj) - { - return Equals(obj as Cookie); - } - /// /// Serves as a hash function for a particular type. /// diff --git a/dotnet/src/webdriver/InitializationScript.cs b/dotnet/src/webdriver/InitializationScript.cs index f102503920b0b..ace8f0c03d890 100644 --- a/dotnet/src/webdriver/InitializationScript.cs +++ b/dotnet/src/webdriver/InitializationScript.cs @@ -55,21 +55,21 @@ internal InitializationScript(string scriptId, string scriptName, string scriptS /// /// Indicates whether the current is equal to another of the same type. /// - /// An to compare with this . - /// if the current is equal to the parameter; otherwise, . - public bool Equals(InitializationScript? other) + /// An to compare with this . + /// if the current is equal to the other parameter; otherwise, . + public override bool Equals(object? obj) { - return other is not null && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource; + return Equals(obj as InitializationScript); } /// /// Indicates whether the current is equal to another of the same type. /// - /// An to compare with this . - /// if the current is equal to the other parameter; otherwise, . - public override bool Equals(object? obj) + /// An to compare with this . + /// if the current is equal to the parameter; otherwise, . + public bool Equals(InitializationScript? other) { - return Equals(obj as InitializationScript); + return other is not null && this.ScriptId == other.ScriptId && this.ScriptName == other.ScriptName && this.ScriptSource == other.ScriptSource; } /// diff --git a/dotnet/src/webdriver/Remote/DesiredCapabilities.cs b/dotnet/src/webdriver/Remote/DesiredCapabilities.cs index 0830ec5b35f86..ef7d15797af84 100644 --- a/dotnet/src/webdriver/Remote/DesiredCapabilities.cs +++ b/dotnet/src/webdriver/Remote/DesiredCapabilities.cs @@ -244,6 +244,21 @@ public override string ToString() return string.Format(CultureInfo.InvariantCulture, "Capabilities [BrowserName={0}, Platform={1}, Version={2}]", this.BrowserName, this.Platform.PlatformType.ToString(), this.Version); } + /// + /// Indicates whether the current is equal to another . + /// + /// you wish to compare. + /// if the current is equal to the other parameter; otherwise, . + public override bool Equals(object? obj) + { + return Equals(obj as DesiredCapabilities); + } + + /// + /// Indicates whether the current is equal to another . + /// + /// An to compare with this . + /// if the current is equal to the parameter; otherwise, . public bool Equals(DesiredCapabilities? other) { if (other is null) @@ -274,16 +289,6 @@ public bool Equals(DesiredCapabilities? other) return true; } - /// - /// Compare two DesiredCapabilities and will return either true or false - /// - /// DesiredCapabilities you wish to compare - /// true if they are the same or false if they are not - public override bool Equals(object? obj) - { - return Equals(obj as DesiredCapabilities); - } - /// /// Returns a read-only version of this capabilities object. /// diff --git a/dotnet/src/webdriver/SessionId.cs b/dotnet/src/webdriver/SessionId.cs index 3428e4e25da22..1379bfdb88cf0 100644 --- a/dotnet/src/webdriver/SessionId.cs +++ b/dotnet/src/webdriver/SessionId.cs @@ -57,22 +57,22 @@ public override int GetHashCode() } /// - /// Indicates whether the current session ID value is the same as . + /// Indicates whether the current session ID value is the same as . /// - /// The session to compare to. + /// The session to compare to. /// if the values are equal; otherwise, . - public bool Equals(SessionId? other) + public override bool Equals(object? obj) { - return other is not null && string.Equals(this.sessionOpaqueKey, other.sessionOpaqueKey); + return Equals(obj as SessionId); } /// - /// Indicates whether the current session ID value is the same as . + /// Indicates whether the current session ID value is the same as . /// - /// The session to compare to. + /// The session to compare to. /// if the values are equal; otherwise, . - public override bool Equals(object? obj) + public bool Equals(SessionId? other) { - return Equals(obj as SessionId); + return other is not null && string.Equals(this.sessionOpaqueKey, other.sessionOpaqueKey); } }