From f0eed173fccd48549cd7578a16451ba5b3188356 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 1 May 2021 23:43:56 +0300 Subject: [PATCH 1/5] add NotNullWhen attribute --- .../Unix/System.Security.Cryptography.Native/Interop.X509.cs | 2 +- .../ref/Microsoft.Extensions.Logging.Abstractions.cs | 2 +- .../Microsoft.Extensions.Logging.Abstractions/src/EventId.cs | 2 +- .../src/Microsoft/Win32/SystemEvents.cs | 2 +- .../ActiveDirectory/DirectoryEntryManager.cs | 2 +- .../src/Polyfills/System.Text.Rune.netstandard20.cs | 2 +- .../System/Text/Json/Serialization/ReferenceEqualsWrapper.cs | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) 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..e238f63dbf3510 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 @@ -411,7 +411,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..9413ec545b6a36 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs @@ -77,7 +77,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..249776e4760822 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs @@ -41,7 +41,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..4582cf49037aa3 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 @@ -387,7 +387,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..c2a20a7746e3ae 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,4 +1,4 @@ -// 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; @@ -9,7 +9,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); } From 724ab163358a7117efaf359a2633e6f00417a9b8 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 1 May 2021 23:45:47 +0300 Subject: [PATCH 2/5] add usings --- .../Unix/System.Security.Cryptography.Native/Interop.X509.cs | 1 + .../Microsoft.Extensions.Logging.Abstractions/src/EventId.cs | 2 ++ .../DirectoryServices/ActiveDirectory/DirectoryEntryManager.cs | 1 + .../src/Polyfills/System.Text.Rune.netstandard20.cs | 1 + .../System/Text/Json/Serialization/ReferenceEqualsWrapper.cs | 1 + 5 files changed, 6 insertions(+) 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 e238f63dbf3510..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 { diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs index 9413ec545b6a36..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 { /// 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 249776e4760822..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 { 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 4582cf49037aa3..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: 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 c2a20a7746e3ae..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 @@ -2,6 +2,7 @@ // 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 { From 9a2093180cac78516611b3e4221c5e605d156c64 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 27 May 2021 23:34:46 +0300 Subject: [PATCH 3/5] revert extensions.logging --- .../ref/Microsoft.Extensions.Logging.Abstractions.cs | 2 +- .../Microsoft.Extensions.Logging.Abstractions/src/EventId.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) 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 57deb72a24a56d..60c0cd253078ea 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([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public override bool Equals(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 972fb1ec0488ce..7e031c5ec5f6b4 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs @@ -1,8 +1,6 @@ // 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 { /// @@ -79,7 +77,7 @@ public bool Equals(EventId other) } /// - public override bool Equals([NotNullWhen(true)] object? obj) + public override bool Equals(object? obj) { if (obj is null) { From ceeaccf5de9b9a2f765a02b00c663d73044ccf57 Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 28 May 2021 01:09:39 +0300 Subject: [PATCH 4/5] return back extensions.abstractions with including NullableAttribute --- .../ref/Microsoft.Extensions.Logging.Abstractions.cs | 2 +- .../ref/Microsoft.Extensions.Logging.Abstractions.csproj | 1 + .../Microsoft.Extensions.Logging.Abstractions/src/EventId.cs | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) 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/ref/Microsoft.Extensions.Logging.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj index 0086184386da10..f7d33cfbcbf456 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj @@ -5,5 +5,6 @@ + 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) { From 9f089bf2d38b6ca13b692954ea830226681f8da2 Mon Sep 17 00:00:00 2001 From: hrrrrustic <35951936+hrrrrustic@users.noreply.github.com> Date: Fri, 28 May 2021 02:10:46 +0300 Subject: [PATCH 5/5] Update src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj Co-authored-by: Buyaa Namnan --- .../ref/Microsoft.Extensions.Logging.Abstractions.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj index f7d33cfbcbf456..0086184386da10 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/ref/Microsoft.Extensions.Logging.Abstractions.csproj @@ -5,6 +5,5 @@ -