From d7833a690746ef74944c1b958e50a8965c25a0f6 Mon Sep 17 00:00:00 2001 From: Paulo Morgado <470455+paulomorgado@users.noreply.github.com> Date: Tue, 7 Jan 2025 14:58:25 +0000 Subject: [PATCH] Use object.ReferenceEquals for reference type equality comparison (#1277) --- src/core/SIP/SIPEndPoint.cs | 2 +- src/core/SIP/SIPParameters.cs | 5 +++-- src/core/SIP/SIPURI.cs | 4 ++-- src/net/STUN/STUNUri.cs | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/SIP/SIPEndPoint.cs b/src/core/SIP/SIPEndPoint.cs index eb9579202..ac5a02f69 100644 --- a/src/core/SIP/SIPEndPoint.cs +++ b/src/core/SIP/SIPEndPoint.cs @@ -244,7 +244,7 @@ public override bool Equals(object obj) public static bool operator ==(SIPEndPoint endPoint1, SIPEndPoint endPoint2) { - if ((object)endPoint1 == null && (object)endPoint2 == null) + if (object.ReferenceEquals(endPoint1, endPoint2)) { return true; } diff --git a/src/core/SIP/SIPParameters.cs b/src/core/SIP/SIPParameters.cs index 8824f16ed..de1bb428e 100644 --- a/src/core/SIP/SIPParameters.cs +++ b/src/core/SIP/SIPParameters.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Filename: SIPParameters.cs // // Description: SIP parameters as used in Contact, To, From and Via SIP headers. @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Runtime.Serialization; using Microsoft.Extensions.Logging; using SIPSorcery.Sys; @@ -337,7 +338,7 @@ public override bool Equals(object obj) /// public static bool operator ==(SIPParameters x, SIPParameters y) { - if (x is null && y is null) + if (object.ReferenceEquals(x, y)) { return true; } diff --git a/src/core/SIP/SIPURI.cs b/src/core/SIP/SIPURI.cs index b6b8c7af4..085109b47 100644 --- a/src/core/SIP/SIPURI.cs +++ b/src/core/SIP/SIPURI.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- // Filename: SIPURI.cs // // Description: SIP URI. @@ -605,7 +605,7 @@ public override bool Equals(object obj) public static bool operator ==(SIPURI uri1, SIPURI uri2) { - if (uri1 is null && uri2 is null) + if (object.ReferenceEquals(uri1, uri2)) { return true; } diff --git a/src/net/STUN/STUNUri.cs b/src/net/STUN/STUNUri.cs index f0a1606cb..a13c2a1b4 100644 --- a/src/net/STUN/STUNUri.cs +++ b/src/net/STUN/STUNUri.cs @@ -268,7 +268,7 @@ public override bool Equals(object obj) public static bool operator ==(STUNUri uri1, STUNUri uri2) { - if (uri1 is null && uri2 is null) + if (object.ReferenceEquals(uri1, uri2)) { return true; }