diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs index 0e5806d1091352..a8a272c60d8282 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs @@ -6,6 +6,7 @@ using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using Microsoft.Win32.SafeHandles; +using System.Diagnostics.CodeAnalysis; internal static partial class Interop { @@ -411,7 +412,7 @@ internal X509VerifyStatusCode(int code) public bool Equals(X509VerifyStatusCode other) => Code == other.Code; - public override bool Equals(object? obj) => obj is X509VerifyStatusCode other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is X509VerifyStatusCode other && Equals(other); public override int GetHashCode() => Code.GetHashCode(); diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs index 60c0cd253078ea..57deb72a24a56d 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.cs @@ -14,7 +14,7 @@ public readonly partial struct EventId public int Id { get { throw null; } } public string? Name { get { throw null; } } public bool Equals(Microsoft.Extensions.Logging.EventId other) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(Microsoft.Extensions.Logging.EventId left, Microsoft.Extensions.Logging.EventId right) { throw null; } public static implicit operator Microsoft.Extensions.Logging.EventId (int i) { throw null; } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs index 7e031c5ec5f6b4..972fb1ec0488ce 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace Microsoft.Extensions.Logging { /// @@ -77,7 +79,7 @@ public bool Equals(EventId other) } /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is null) { diff --git a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs index 374070553e4336..8a63c86930e08c 100644 --- a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs +++ b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs @@ -1353,7 +1353,7 @@ private void InvokeCallback(object? arg) _delegate.DynamicInvoke((object[]?)arg); } - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { return other is SystemEventInvokeInfo otherInvoke && otherInvoke._delegate.Equals(_delegate); } diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs index d30f70c40eb2ea..89c1c6b7ddc276 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs @@ -3,6 +3,7 @@ using System.Collections; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.DirectoryServices.ActiveDirectory { @@ -41,7 +42,7 @@ public bool Equals(DistinguishedName dn) return result; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is DistinguishedName other) { diff --git a/src/libraries/System.Text.Encodings.Web/src/Polyfills/System.Text.Rune.netstandard20.cs b/src/libraries/System.Text.Encodings.Web/src/Polyfills/System.Text.Rune.netstandard20.cs index f99e39b691ce47..66c637eda2a2b1 100644 --- a/src/libraries/System.Text.Encodings.Web/src/Polyfills/System.Text.Rune.netstandard20.cs +++ b/src/libraries/System.Text.Encodings.Web/src/Polyfills/System.Text.Rune.netstandard20.cs @@ -6,6 +6,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text.Encodings.Web; +using System.Diagnostics.CodeAnalysis; // Contains a polyfill implementation of System.Text.Rune that works on netstandard2.0. // Implementation copied from: @@ -387,7 +388,7 @@ public static OperationStatus DecodeFromUtf8(ReadOnlySpan source, out Rune return OperationStatus.NeedMoreData; } - public override bool Equals(object? obj) => (obj is Rune other) && Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => (obj is Rune other) && Equals(other); public bool Equals(Rune other) => this == other; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceEqualsWrapper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceEqualsWrapper.cs index dc292e2213096c..d905ff9ee75557 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceEqualsWrapper.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReferenceEqualsWrapper.cs @@ -1,7 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; namespace System.Text.Json.Serialization { @@ -9,7 +10,7 @@ internal struct ReferenceEqualsWrapper : IEquatable { private object _object; public ReferenceEqualsWrapper(object obj) => _object = obj; - public override bool Equals(object? obj) => obj is ReferenceEqualsWrapper otherObj && Equals(otherObj); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is ReferenceEqualsWrapper otherObj && Equals(otherObj); public bool Equals(ReferenceEqualsWrapper obj) => ReferenceEquals(_object, obj._object); public override int GetHashCode() => RuntimeHelpers.GetHashCode(_object); }