From 2b0e2785e546a38e9bf401d71650514fa00cf1b8 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 30 Jan 2021 06:09:28 -0500 Subject: [PATCH] Use [NotNullWhen(true)] in more places (#47598) * Use [NotNullWhen(true)] in more places Did a quick search/audit for methods that returned bool and took nullable object as the first input, and added [NotNullWhen(true)] where it was obviously correct. * Address PR feedback --- .../api-guidelines/nullability.md | 1 + .../src/System/Delegate.CoreCLR.cs | 2 +- .../System/Diagnostics/SymbolStore/Token.cs | 4 +- .../src/System/Enum.CoreCLR.cs | 3 +- .../src/System/MulticastDelegate.cs | 2 +- .../src/System/RuntimeHandles.cs | 2 +- .../src/System/ValueType.cs | 2 +- .../System.Console/ref/System.Console.cs | 2 +- .../src/System/ConsoleKeyInfo.cs | 4 +- ...em.Diagnostics.DiagnosticSourceActivity.cs | 8 +- .../src/System/Diagnostics/Activity.cs | 4 +- .../src/System/Diagnostics/ActivityContext.cs | 3 +- .../src/System/Diagnostics/ActivityLink.cs | 3 +- .../ref/System.Diagnostics.StackTrace.cs | 2 +- .../Diagnostics/SymbolStore/SymbolToken.cs | 4 +- .../ref/System.Drawing.Common.cs | 18 +- .../src/System/Drawing/CharacterRange.cs | 2 +- .../src/System/Drawing/Drawing2D/Matrix.cs | 3 +- .../src/System/Drawing/Font.cs | 3 +- .../src/System/Drawing/FontFamily.Unix.cs | 4 +- .../src/System/Drawing/FontFamily.Windows.cs | 4 +- .../src/System/Drawing/ImageAnimator.Unix.cs | 3 +- .../System/Drawing/ImageAnimator.Windows.cs | 4 +- .../System/Drawing/Imaging/FrameDimension.cs | 4 +- .../src/System/Drawing/Imaging/ImageFormat.cs | 3 +- .../src/System/Drawing/Printing/Margins.cs | 3 +- .../Drawing/ToolboxBitmapAttribute.Unix.cs | 3 +- .../System/Drawing/ToolboxBitmapAttribute.cs | 2 +- .../ref/System.Drawing.Primitives.cs | 12 +- .../src/System/Drawing/Color.cs | 3 +- .../src/System/Drawing/Point.cs | 3 +- .../src/System/Drawing/PointF.cs | 3 +- .../src/System/Drawing/Rectangle.cs | 3 +- .../src/System/Drawing/RectangleF.cs | 3 +- .../src/System/Drawing/Size.cs | 3 +- .../src/System/Drawing/SizeF.cs | 3 +- .../ref/System.Formats.Asn1.cs | 2 +- .../src/System/Formats/Asn1/Asn1Tag.cs | 3 +- .../src/System/Formats/Asn1/AsnWriter.cs | 3 +- .../ref/System.Linq.Expressions.cs | 2 +- .../src/System/Dynamic/BindingRestrictions.cs | 6 +- .../src/System/Dynamic/CallInfo.cs | 3 +- .../Expressions/Compiler/BoundConstants.cs | 5 +- .../Expressions/Interpreter/LocalVariables.cs | 2 +- .../ref/System.Memory.Data.cs | 2 +- .../src/System/BinaryData.cs | 3 +- .../System.Memory/ref/System.Memory.cs | 4 +- .../src/System/SequencePosition.cs | 3 +- .../System.Net.Http/ref/System.Net.Http.cs | 40 ++-- .../Http/Headers/AuthenticationHeaderValue.cs | 2 +- .../Net/Http/Headers/ByteArrayHeaderParser.cs | 2 +- .../Http/Headers/CacheControlHeaderValue.cs | 2 +- .../Headers/ContentDispositionHeaderValue.cs | 2 +- .../Http/Headers/ContentRangeHeaderValue.cs | 2 +- .../Net/Http/Headers/DateHeaderParser.cs | 2 +- .../Net/Http/Headers/EntityTagHeaderValue.cs | 2 +- .../Net/Http/Headers/MediaTypeHeaderValue.cs | 2 +- .../Net/Http/Headers/NameValueHeaderValue.cs | 2 +- .../NameValueWithParametersHeaderValue.cs | 2 +- .../Net/Http/Headers/ProductHeaderValue.cs | 2 +- .../Http/Headers/ProductInfoHeaderParser.cs | 2 +- .../Http/Headers/ProductInfoHeaderValue.cs | 2 +- .../Http/Headers/RangeConditionHeaderValue.cs | 2 +- .../Net/Http/Headers/RangeHeaderValue.cs | 2 +- .../Net/Http/Headers/RangeItemHeaderValue.cs | 3 +- .../Http/Headers/RetryConditionHeaderValue.cs | 2 +- .../Headers/StringWithQualityHeaderValue.cs | 2 +- .../Http/Headers/TransferCodingHeaderValue.cs | 2 +- .../Net/Http/Headers/UriHeaderParser.cs | 2 +- .../System/Net/Http/Headers/ViaHeaderValue.cs | 2 +- .../Net/Http/Headers/WarningHeaderValue.cs | 2 +- .../src/System/Net/Http/HttpMethod.cs | 5 +- .../Http/SocketsHttpHandler/HttpAuthority.cs | 5 +- .../SocketsHttpHandler/HttpConnectionPool.cs | 3 +- .../HttpConnectionPoolManager.cs | 3 +- .../src/System/Net/Managed/ListenerPrefix.cs | 4 +- .../System.Net.Mail/ref/System.Net.Mail.cs | 6 +- .../src/System/Net/Mail/MailAddress.cs | 2 +- .../src/System/Net/Mime/ContentDisposition.cs | 2 +- .../src/System/Net/Mime/ContentType.cs | 2 +- .../ref/System.Net.NetworkInformation.cs | 2 +- .../Net/NetworkInformation/PhysicalAddress.cs | 2 +- .../ref/System.Net.Primitives.cs | 8 +- .../src/System/Net/Cookie.cs | 2 +- .../src/System/Net/CredentialCache.cs | 7 +- .../src/System/Net/DnsEndPoint.cs | 3 +- .../src/System/Net/IPAddress.cs | 2 +- .../src/System/Net/IPEndPoint.cs | 2 +- .../ref/System.Net.Security.cs | 2 +- .../Net/Security/SslApplicationProtocol.cs | 3 +- .../System/Net/Security/SslSessionsCache.cs | 3 +- .../ref/System.Net.Sockets.cs | 4 +- .../System/Net/Sockets/IPPacketInformation.cs | 4 +- .../System/Net/Sockets/UdpReceiveResult.cs | 4 +- .../ref/System.Numerics.Vectors.cs | 16 +- .../ref/System.ObjectModel.cs | 2 +- .../ComponentModel/TypeConverterAttribute.cs | 2 +- .../src/System/ApplicationId.cs | 3 +- .../src/System/ArraySegment.cs | 3 +- .../src/System/Attribute.cs | 2 +- .../src/System/Boolean.cs | 2 +- .../src/System/Buffers/StandardFormat.cs | 3 +- .../System.Private.CoreLib/src/System/Byte.cs | 2 +- .../System.Private.CoreLib/src/System/Char.cs | 2 +- .../System/Collections/Generic/Comparer.cs | 8 +- .../Collections/Generic/EqualityComparer.cs | 10 +- .../Generic/HashSetEqualityComparer.cs | 4 +- .../ComponentModel/DefaultValueAttribute.cs | 2 +- .../EditorBrowsableAttribute.cs | 4 +- .../src/System/Convert.cs | 8 +- .../src/System/DateTime.cs | 2 +- .../src/System/DateTimeOffset.cs | 2 +- .../src/System/Decimal.cs | 2 +- .../Diagnostics/Tracing/EventDescriptor.cs | 3 +- .../src/System/Double.cs | 2 +- .../System.Private.CoreLib/src/System/Enum.cs | 4 +- .../src/System/Globalization/CompareInfo.cs | 2 +- .../src/System/Globalization/CultureInfo.cs | 3 +- .../src/System/Globalization/IdnMapping.cs | 3 +- .../src/System/Globalization/RegionInfo.cs | 3 +- .../src/System/Globalization/SortKey.cs | 3 +- .../src/System/Globalization/SortVersion.cs | 5 +- .../src/System/Globalization/StringInfo.cs | 2 +- .../src/System/Globalization/TextInfo.cs | 3 +- .../System.Private.CoreLib/src/System/Guid.cs | 2 +- .../System.Private.CoreLib/src/System/Half.cs | 2 +- .../src/System/IO/Path.cs | 2 +- .../src/System/Index.cs | 3 +- .../src/System/Int16.cs | 2 +- .../src/System/Int32.cs | 2 +- .../src/System/Int64.cs | 2 +- .../src/System/IntPtr.cs | 7 +- .../src/System/Memory.cs | 3 +- .../src/System/Numerics/Matrix3x2.cs | 3 +- .../src/System/Numerics/Matrix4x4.cs | 3 +- .../src/System/Numerics/Plane.cs | 3 +- .../src/System/Numerics/Quaternion.cs | 3 +- .../src/System/Numerics/Vector2.cs | 3 +- .../src/System/Numerics/Vector3.cs | 3 +- .../src/System/Numerics/Vector4.cs | 3 +- .../src/System/Numerics/Vector_1.cs | 3 +- .../src/System/Range.cs | 3 +- .../src/System/ReadOnlyMemory.cs | 3 +- .../InteropServices/ArrayWithOffset.cs | 3 +- .../System/Runtime/InteropServices/CLong.cs | 3 +- .../System/Runtime/InteropServices/CULong.cs | 3 +- .../Runtime/InteropServices/GCHandle.cs | 3 +- .../System/Runtime/InteropServices/NFloat.cs | 3 +- .../System/Runtime/Intrinsics/Vector128_1.cs | 3 +- .../System/Runtime/Intrinsics/Vector256_1.cs | 3 +- .../System/Runtime/Intrinsics/Vector64_1.cs | 3 +- .../Runtime/Serialization/StreamingContext.cs | 4 +- .../Runtime/Versioning/FrameworkName.cs | 5 +- .../src/System/SByte.cs | 2 +- .../src/System/Security/SecurityElement.cs | 11 +- .../src/System/Single.cs | 2 +- .../src/System/String.Comparison.cs | 7 +- .../src/System/StringComparer.cs | 5 +- .../System/Text/DecoderExceptionFallback.cs | 2 +- .../System/Text/DecoderReplacementFallback.cs | 3 +- .../System/Text/EncoderExceptionFallback.cs | 3 +- .../System/Text/EncoderReplacementFallback.cs | 3 +- .../src/System/Text/Encoding.cs | 2 +- .../src/System/Text/EncodingInfo.cs | 4 +- .../src/System/Text/Rune.cs | 3 +- .../src/System/Text/StringBuilder.cs | 9 +- .../src/System/Text/UTF32Encoding.cs | 3 +- .../src/System/Text/UTF7Encoding.cs | 4 +- .../src/System/Text/UTF8Encoding.cs | 3 +- .../src/System/Text/UnicodeEncoding.cs | 3 +- .../src/System/Threading/CancellationToken.cs | 2 +- .../CancellationTokenRegistration.cs | 3 +- .../src/System/Threading/ExecutionContext.cs | 2 +- .../System/Threading/LowLevelLifoSemaphore.cs | 3 +- .../PortableThreadPool.ThreadCounts.cs | 3 +- .../PortableThreadPool.WorkerTracking.cs | 3 +- .../src/System/Threading/Tasks/ValueTask.cs | 4 +- .../src/System/TimeSpan.cs | 2 +- .../src/System/TimeZoneInfo.AdjustmentRule.cs | 3 +- .../src/System/TimeZoneInfo.TransitionTime.cs | 3 +- .../src/System/TimeZoneInfo.cs | 5 +- .../src/System/Tuple.cs | 49 ++--- .../src/System/UInt16.cs | 2 +- .../src/System/UInt32.cs | 2 +- .../src/System/UInt64.cs | 2 +- .../src/System/UIntPtr.cs | 7 +- .../src/System/ValueTuple.cs | 19 +- .../src/System/Version.cs | 4 +- .../src/System/Xml/PrefixHandle.cs | 8 +- .../src/System/Xml/StringHandle.cs | 4 +- .../src/System/Xml/UniqueId.cs | 4 +- .../InteropServices/JavaScript/JSObject.cs | 3 +- .../System.Private.Uri/src/System/Uri.cs | 5 +- .../src/System/UriBuilder.cs | 2 +- .../System.Private.Uri/src/System/UriExt.cs | 2 +- .../src/System/Xml/Linq/XName.cs | 2 +- .../src/System/Xml/Linq/XNamespace.cs | 2 +- .../System/Xml/BinaryXml/XmlBinaryReader.cs | 3 +- .../Xml/Cache/XPathDocumentNavigator.cs | 3 +- .../src/System/Xml/Cache/XPathNodeInfoAtom.cs | 3 +- .../System/Xml/Dom/DocumentXPathNavigator.cs | 2 +- .../src/System/Xml/Schema/BitSet.cs | 9 +- .../src/System/Xml/Schema/Chameleonkey.cs | 13 +- .../src/System/Xml/Schema/ConstraintStruct.cs | 19 +- .../src/System/Xml/Schema/XmlSchemaType.cs | 2 +- .../System/Xml/Serialization/Compilation.cs | 2 +- .../src/System/Xml/Serialization/NameTable.cs | 4 +- .../System/Xml/Serialization/SourceInfo.cs | 3 +- .../System/Xml/Serialization/XmlSerializer.cs | 35 ++-- .../src/System/Xml/XmlQualifiedName.cs | 3 +- .../src/System/Xml/Xsl/Pair.cs | 3 +- .../src/System/Xml/Xsl/QIL/QilName.cs | 2 +- .../src/System/Xml/Xsl/XmlQueryCardinality.cs | 3 +- .../src/System/Xml/Xsl/XmlQueryType.cs | 5 +- .../Xml/Xsl/Xslt/CompilerScopeManager.cs | 2 +- ...time.InteropServices.RuntimeInformation.cs | 2 +- .../RuntimeInformation/OSPlatform.cs | 4 +- .../ref/System.Runtime.InteropServices.cs | 8 +- .../ref/System.Runtime.Intrinsics.cs | 6 +- .../ref/System.Runtime.Numerics.cs | 4 +- .../src/System/Numerics/BigInteger.cs | 2 +- .../src/System/Numerics/Complex.cs | 2 +- .../Runtime/Serialization/MemberHolder.cs | 2 +- .../ref/System.Runtime.Serialization.Xml.cs | 2 +- .../System.Runtime/ref/System.Runtime.cs | 198 +++++++++--------- .../ref/System.Security.AccessControl.cs | 2 +- .../src/System/Security/AccessControl/ACE.cs | 2 +- .../ref/System.Security.Claims.cs | 2 +- .../Security/Claims/GenericPrincipal.cs | 3 +- ...System.Security.Cryptography.Algorithms.cs | 4 +- .../Cryptography/RSAEncryptionPadding.cs | 5 +- .../Cryptography/RSASignaturePadding.cs | 5 +- .../ref/System.Security.Cryptography.Cng.cs | 16 +- .../Security/Cryptography/CngAlgorithm.cs | 5 +- .../Cryptography/CngAlgorithmGroup.cs | 5 +- .../Security/Cryptography/CngKeyBlobFormat.cs | 5 +- .../Security/Cryptography/CngProperty.cs | 3 +- .../Security/Cryptography/CngProvider.cs | 5 +- ...System.Security.Cryptography.Primitives.cs | 2 +- .../Cryptography/HashAlgorithmName.cs | 4 +- ....Security.Cryptography.X509Certificates.cs | 4 +- .../X509Certificates/X509Certificate.cs | 5 +- .../ref/System.Security.Principal.Windows.cs | 4 +- .../System/Security/Principal/NTAccount.cs | 3 +- .../src/System/Security/Principal/SID.cs | 2 +- ...System.ServiceProcess.ServiceController.cs | 2 +- .../SessionChangeDescription.cs | 4 +- .../src/System/Text/DecoderBestFitFallback.cs | 5 +- .../src/System/Text/EncoderBestFitFallback.cs | 3 +- .../ref/System.Text.Encoding.Extensions.cs | 8 +- .../System.Text.Json/ref/System.Text.Json.cs | 2 +- .../src/System/Text/Json/JsonEncodedText.cs | 3 +- .../Text/Json/Serialization/JsonClassInfo.cs | 3 +- .../Text/RegularExpressions/Regex.Cache.cs | 2 +- .../ref/System.Threading.Tasks.Dataflow.cs | 2 +- .../src/Base/DataflowMessageHeader.cs | 3 +- .../System.Threading/ref/System.Threading.cs | 4 +- .../src/System/Threading/LockCookie.cs | 4 +- .../ref/System.Transactions.Local.cs | 4 +- .../Transactions/EnlistmentTraceIdentifier.cs | 4 +- .../src/System/Transactions/Transaction.cs | 2 +- .../System/Transactions/TransactionOptions.cs | 4 +- .../TransactionTraceIdentifier.cs | 4 +- .../ref/System.Xml.ReaderWriter.cs | 4 +- .../ref/System.Xml.XDocument.cs | 4 +- .../src/System/Delegate.Mono.cs | 2 +- .../src/System/ModuleHandle.cs | 3 +- .../src/System/MulticastDelegate.cs | 2 +- .../src/System/ValueType.cs | 3 +- 269 files changed, 716 insertions(+), 554 deletions(-) diff --git a/docs/coding-guidelines/api-guidelines/nullability.md b/docs/coding-guidelines/api-guidelines/nullability.md index 8982b9ad69ddf..7e7a6a6e83bfc 100644 --- a/docs/coding-guidelines/api-guidelines/nullability.md +++ b/docs/coding-guidelines/api-guidelines/nullability.md @@ -96,6 +96,7 @@ The C# compiler respects a set of attributes that impact its flow analysis. We - **DO** annotate properties where a getter will never return `null` but a setter allows `null` as being non-nullable but also `[AllowNull]`. - **DO** annotate properties where a getter may return `null` but a setter throws for `null` as being nullable but also `[DisallowNull]`. - **DO** add `[NotNullWhen(true)]` to nullable arguments of `Try` methods that will definitively be non-`null` if the method returns `true`. For example, if `Int32.TryParse(string? s)` returns `true`, `s` is known to not be `null`, and so the method should be `public static bool TryParse([NotNullWhen(true)] string? s, out int result)`. +- **DO** add `[NotNullWhen(true)]` to overrides of `public virtual bool Equals(object? obj)`, except in the extremely rare circumstance where a non-null instance may compare equally to `null` (one example of where it's not valid is on `Nullable`). - **DO** add `[NotNullIfNotNull(string)]` if nullable ref argument will be non-`null` upon exit, when an other argument passed evaluated to non-`null`, pass that argument name as string. Example: `public void Exchange([NotNullIfNotNull("value")] ref object? location, object? value);`. - **DO** add `[return: NotNullIfNotNull(string)]` if a method would not return `null` in case an argument passed evaluated to non-`null`, pass that argument name as string. Example: `[return: NotNullIfNotNull("name")] public string? FormatName(string? name);` - **DO** add `[MemberNotNull(string fieldName)]` to a helper method which initializes member field(s), passing in the field name. Example: `[MemberNotNull("_buffer")] private void InitializeBuffer()`. This will help to avoid spurious warnings at call sites that call the initialization method and then proceed to use the specified field. Note that there are two constructors to `MemberNotNull`; one that takes a single `string`, and one that takes a `params string[]`. When the number of fields initialized is small (e.g. <= 3), it's preferable to use multiple `[MemberNotNull(string)]` attributes on the method rather than one `[MemberNotNull(string, string, string, ...)]` attribute, as the latter is not CLS compliant and will likely require `#pragma warning disable` and `#pragma warning restore` around the line to suppress warnings. diff --git a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs index fef2f90be0f68..23567e475d99b 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs @@ -93,7 +93,7 @@ protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.Al } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null || !InternalEqualTypes(this, obj)) return false; diff --git a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/SymbolStore/Token.cs b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/SymbolStore/Token.cs index 74dd84c3ef370..fbd9f7e4bc1ae 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/SymbolStore/Token.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/SymbolStore/Token.cs @@ -9,6 +9,8 @@ ** ===========================================================*/ +using System.Diagnostics.CodeAnalysis; + namespace System.Diagnostics.SymbolStore { internal struct SymbolToken @@ -21,7 +23,7 @@ internal struct SymbolToken public override int GetHashCode() { return m_token; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is SymbolToken) return Equals((SymbolToken)obj); diff --git a/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs index 3dded2f8d367d..3808942cbdd39 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs @@ -1,6 +1,7 @@ // 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; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -13,7 +14,7 @@ public abstract partial class Enum private static extern void GetEnumValuesAndNames(QCallTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, Interop.BOOL getNames); [MethodImpl(MethodImplOptions.InternalCall)] - public extern override bool Equals(object? obj); + public extern override bool Equals([NotNullWhen(true)] object? obj); [MethodImpl(MethodImplOptions.InternalCall)] private static extern object InternalBoxEnum(RuntimeType enumType, long value); diff --git a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs index f650ffae48ab2..6abac717392c3 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -54,7 +54,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont // equals returns true IIF the delegate is not null and has the // same target, method and invocation list as this object - public sealed override bool Equals(object? obj) + public sealed override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null) return false; diff --git a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs index d5b56e11e99db..7dfcb3a5e593a 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -1246,7 +1246,7 @@ public override int GetHashCode() return m_ptr != null ? m_ptr.GetHashCode() : 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is ModuleHandle)) return false; diff --git a/src/coreclr/System.Private.CoreLib/src/System/ValueType.cs b/src/coreclr/System.Private.CoreLib/src/System/ValueType.cs index 72ffecfe902df..e15ad7512c819 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/ValueType.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/ValueType.cs @@ -22,7 +22,7 @@ public abstract class ValueType { [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "Trimmed fields don't make a difference for equality")] - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (null == obj) { diff --git a/src/libraries/System.Console/ref/System.Console.cs b/src/libraries/System.Console/ref/System.Console.cs index 7a342d5268563..e0dd53846f457 100644 --- a/src/libraries/System.Console/ref/System.Console.cs +++ b/src/libraries/System.Console/ref/System.Console.cs @@ -310,7 +310,7 @@ public enum ConsoleKey public char KeyChar { get { throw null; } } public System.ConsoleModifiers Modifiers { get { throw null; } } public bool Equals(System.ConsoleKeyInfo obj) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.ConsoleKeyInfo a, System.ConsoleKeyInfo b) { throw null; } public static bool operator !=(System.ConsoleKeyInfo a, System.ConsoleKeyInfo b) { throw null; } diff --git a/src/libraries/System.Console/src/System/ConsoleKeyInfo.cs b/src/libraries/System.Console/src/System/ConsoleKeyInfo.cs index f0f2e36479a08..7811b703f3186 100644 --- a/src/libraries/System.Console/src/System/ConsoleKeyInfo.cs +++ b/src/libraries/System.Console/src/System/ConsoleKeyInfo.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 System { public readonly struct ConsoleKeyInfo : IEquatable @@ -46,7 +48,7 @@ public ConsoleModifiers Modifiers get { return _mods; } } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { return value is ConsoleKeyInfo info && Equals(info); } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs index e04d9f79293d5..1ea27dc59d46f 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSourceActivity.cs @@ -132,7 +132,7 @@ public void CopyTo(System.Span destination) { } public static System.Diagnostics.ActivitySpanId CreateFromUtf8String(System.ReadOnlySpan idData) { throw null; } public static System.Diagnostics.ActivitySpanId CreateRandom() { throw null; } public bool Equals(System.Diagnostics.ActivitySpanId spanId) { 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 ==(System.Diagnostics.ActivitySpanId spanId1, System.Diagnostics.ActivitySpanId spandId2) { throw null; } public static bool operator !=(System.Diagnostics.ActivitySpanId spanId1, System.Diagnostics.ActivitySpanId spandId2) { throw null; } @@ -171,7 +171,7 @@ public void CopyTo(System.Span destination) { } public static System.Diagnostics.ActivityTraceId CreateFromUtf8String(System.ReadOnlySpan idData) { throw null; } public static System.Diagnostics.ActivityTraceId CreateRandom() { throw null; } public bool Equals(System.Diagnostics.ActivityTraceId traceId) { 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 ==(System.Diagnostics.ActivityTraceId traceId1, System.Diagnostics.ActivityTraceId traceId2) { throw null; } public static bool operator !=(System.Diagnostics.ActivityTraceId traceId1, System.Diagnostics.ActivityTraceId traceId2) { throw null; } @@ -227,7 +227,7 @@ public readonly struct ActivityEvent public static bool operator ==(System.Diagnostics.ActivityContext left, System.Diagnostics.ActivityContext right) { throw null; } public static bool operator !=(System.Diagnostics.ActivityContext left, System.Diagnostics.ActivityContext right) { throw null; } public bool Equals(System.Diagnostics.ActivityContext value) { 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 readonly struct ActivityLink : IEquatable @@ -235,7 +235,7 @@ public readonly struct ActivityEvent public ActivityLink(System.Diagnostics.ActivityContext context, System.Diagnostics.ActivityTagsCollection? tags = null) { throw null; } public System.Diagnostics.ActivityContext Context { get { throw null; } } public System.Collections.Generic.IEnumerable>? Tags { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Diagnostics.ActivityLink value) { throw null; } public static bool operator ==(System.Diagnostics.ActivityLink left, System.Diagnostics.ActivityLink right) { throw null; } public static bool operator !=(System.Diagnostics.ActivityLink left, System.Diagnostics.ActivityLink right) { throw null; } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs index a6d459162c61e..0e278ecea37b8 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Activity.cs @@ -1763,7 +1763,7 @@ public bool Equals(ActivityTraceId traceId) { return _hexString == traceId._hexString; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is ActivityTraceId traceId) return _hexString == traceId._hexString; @@ -1948,7 +1948,7 @@ public bool Equals(ActivitySpanId spanId) { return _hexString == spanId._hexString; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is ActivitySpanId spanId) return _hexString == spanId._hexString; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityContext.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityContext.cs index 0522cbfb7dce8..07710b6e69586 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityContext.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityContext.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace System.Diagnostics { @@ -95,7 +96,7 @@ public static ActivityContext Parse(string traceParent, string? traceState) public bool Equals(ActivityContext value) => SpanId.Equals(value.SpanId) && TraceId.Equals(value.TraceId) && TraceFlags == value.TraceFlags && TraceState == value.TraceState && IsRemote == value.IsRemote; - public override bool Equals(object? obj) => (obj is ActivityContext context) ? Equals(context) : false; + public override bool Equals([NotNullWhen(true)] object? obj) => (obj is ActivityContext context) ? Equals(context) : false; public static bool operator ==(ActivityContext left, ActivityContext right) => left.Equals(right); public static bool operator !=(ActivityContext left, ActivityContext right) => !(left == right); } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityLink.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityLink.cs index 9d3744dededdb..3880f83356f23 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityLink.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/ActivityLink.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace System.Diagnostics { @@ -34,7 +35,7 @@ public ActivityLink(ActivityContext context, ActivityTagsCollection? tags = null /// public IEnumerable>? Tags { get; } - public override bool Equals(object? obj) => (obj is ActivityLink link) && this.Equals(link); + public override bool Equals([NotNullWhen(true)] object? obj) => (obj is ActivityLink link) && this.Equals(link); public bool Equals(ActivityLink value) => Context == value.Context && value.Tags == Tags; public static bool operator ==(ActivityLink left, ActivityLink right) => left.Equals(right); diff --git a/src/libraries/System.Diagnostics.StackTrace/ref/System.Diagnostics.StackTrace.cs b/src/libraries/System.Diagnostics.StackTrace/ref/System.Diagnostics.StackTrace.cs index 46fd6d68b0ce7..03439b54e5f01 100644 --- a/src/libraries/System.Diagnostics.StackTrace/ref/System.Diagnostics.StackTrace.cs +++ b/src/libraries/System.Diagnostics.StackTrace/ref/System.Diagnostics.StackTrace.cs @@ -174,7 +174,7 @@ public readonly partial struct SymbolToken private readonly int _dummyPrimitive; public SymbolToken(int val) { throw null; } public bool Equals(System.Diagnostics.SymbolStore.SymbolToken obj) { 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 int GetToken() { throw null; } public static bool operator ==(System.Diagnostics.SymbolStore.SymbolToken a, System.Diagnostics.SymbolStore.SymbolToken b) { throw null; } diff --git a/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/SymbolStore/SymbolToken.cs b/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/SymbolStore/SymbolToken.cs index baa45a67dab31..b6a894f144fc9 100644 --- a/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/SymbolStore/SymbolToken.cs +++ b/src/libraries/System.Diagnostics.StackTrace/src/System/Diagnostics/SymbolStore/SymbolToken.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 System.Diagnostics.SymbolStore { public readonly struct SymbolToken @@ -16,7 +18,7 @@ public SymbolToken(int val) public override int GetHashCode() => _token; - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is SymbolToken) return Equals((SymbolToken)obj); diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index b6850ab97ef31..7cd79b1d02397 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -232,7 +232,7 @@ public partial struct CharacterRange public CharacterRange(int First, int Length) { throw null; } public int First { get { throw null; } set { } } public int Length { get { throw null; } set { } } - 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 ==(System.Drawing.CharacterRange cr1, System.Drawing.CharacterRange cr2) { throw null; } public static bool operator !=(System.Drawing.CharacterRange cr1, System.Drawing.CharacterRange cr2) { throw null; } @@ -322,7 +322,7 @@ public Font(string familyName, float emSize, System.Drawing.GraphicsUnit unit) { public System.Drawing.GraphicsUnit Unit { get { throw null; } } public object Clone() { throw null; } public void Dispose() { } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } ~Font() { } public static System.Drawing.Font FromHdc(System.IntPtr hdc) { throw null; } public static System.Drawing.Font FromHfont(System.IntPtr hfont) { throw null; } @@ -376,7 +376,7 @@ public FontFamily(string name, System.Drawing.Text.FontCollection? fontCollectio public static System.Drawing.FontFamily GenericSerif { get { throw null; } } public string Name { get { throw null; } } public void Dispose() { } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } ~FontFamily() { } public int GetCellAscent(System.Drawing.FontStyle style) { throw null; } public int GetCellDescent(System.Drawing.FontStyle style) { throw null; } @@ -774,7 +774,7 @@ public sealed partial class ImageAnimator { internal ImageAnimator() { } public static void Animate(System.Drawing.Image image, System.EventHandler onFrameChangedHandler) { } - public static bool CanAnimate(System.Drawing.Image? image) { throw null; } + public static bool CanAnimate([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Drawing.Image? image) { throw null; } public static void StopAnimate(System.Drawing.Image image, System.EventHandler onFrameChangedHandler) { } public static void UpdateFrames() { } public static void UpdateFrames(System.Drawing.Image image) { } @@ -1266,7 +1266,7 @@ public partial class ToolboxBitmapAttribute : System.Attribute public ToolboxBitmapAttribute(string imageFile) { } public ToolboxBitmapAttribute(System.Type t) { } public ToolboxBitmapAttribute(System.Type t, string name) { } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public System.Drawing.Image? GetImage(object? component) { throw null; } public System.Drawing.Image? GetImage(object? component, bool large) { throw null; } @@ -1660,7 +1660,7 @@ public Matrix(float m11, float m12, float m21, float m22, float dx, float dy) { public float OffsetY { get { throw null; } } public System.Drawing.Drawing2D.Matrix Clone() { throw null; } public void Dispose() { } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } ~Matrix() { } public override int GetHashCode() { throw null; } public void Invert() { } @@ -2246,7 +2246,7 @@ public FrameDimension(System.Guid guid) { } public static System.Drawing.Imaging.FrameDimension Page { get { throw null; } } public static System.Drawing.Imaging.FrameDimension Resolution { get { throw null; } } public static System.Drawing.Imaging.FrameDimension Time { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -2364,7 +2364,7 @@ public ImageFormat(System.Guid guid) { } public static System.Drawing.Imaging.ImageFormat Png { get { throw null; } } public static System.Drawing.Imaging.ImageFormat Tiff { get { throw null; } } public static System.Drawing.Imaging.ImageFormat Wmf { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -2557,7 +2557,7 @@ public Margins(int left, int right, int top, int bottom) { } public int Right { get { throw null; } set { } } public int Top { get { throw null; } set { } } public object Clone() { 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 ==(System.Drawing.Printing.Margins? m1, System.Drawing.Printing.Margins? m2) { throw null; } public static bool operator !=(System.Drawing.Printing.Margins? m1, System.Drawing.Printing.Margins? m2) { throw null; } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/CharacterRange.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/CharacterRange.cs index 887ca2794ca9e..157533b84283c 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/CharacterRange.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/CharacterRange.cs @@ -39,7 +39,7 @@ public int Length set => _length = value; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is CharacterRange cr)) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/Matrix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/Matrix.cs index 3c6fe9674cabb..6416a58b77578 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/Matrix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/Matrix.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.InteropServices; using Gdip = System.Drawing.SafeNativeMethods.Gdip; @@ -262,7 +263,7 @@ public bool IsIdentity return isIdentity != 0; } } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is Matrix matrix2)) return false; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs index a1b970ef03138..f2c6e339e2b79 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Serialization; @@ -224,7 +225,7 @@ public float GetHeight(float dpi) /// Returns a value indicating whether the specified object is a equivalent to this /// . /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == this) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Unix.cs index 2a1a243fa8102..9724ec7b86f1a 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Unix.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 System.Drawing { /// @@ -8,7 +10,7 @@ namespace System.Drawing /// public sealed partial class FontFamily : MarshalByRefObject, IDisposable { - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == this) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Windows.cs index 7bfcbabb01ee8..a83331b1b0a69 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/FontFamily.Windows.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 System.Drawing { /// @@ -8,7 +10,7 @@ namespace System.Drawing /// public sealed partial class FontFamily : MarshalByRefObject, IDisposable { - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == this) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs index 157bf76a70700..807dcc81fe08f 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Unix.cs @@ -33,6 +33,7 @@ // using System.Collections; +using System.Diagnostics.CodeAnalysis; using System.Drawing.Imaging; using System.Threading; @@ -106,7 +107,7 @@ public static void Animate(Image image, EventHandler onFrameChangedHandler) thread.Start(); } - public static bool CanAnimate(Image? image) + public static bool CanAnimate([NotNullWhen(true)] Image? image) { if (image == null) return false; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs index d837be3d508f6..4f518384c550f 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.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 System.Drawing { using System.Collections.Generic; @@ -278,7 +280,7 @@ public static void Animate(Image image, EventHandler onFrameChangedHandler) /// /// Whether or not the image has multiple time-based frames. /// - public static bool CanAnimate(Image? image) + public static bool CanAnimate([NotNullWhen(true)] Image? image) { if (image == null) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/FrameDimension.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/FrameDimension.cs index 2f9dca5c714d1..5fc556efad7fc 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/FrameDimension.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/FrameDimension.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 System.Drawing.Imaging { public sealed class FrameDimension @@ -55,7 +57,7 @@ public static FrameDimension Page /// Returns a value indicating whether the specified object is an equivalent to /// this . /// - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { FrameDimension? format = o as FrameDimension; if (format == null) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs index 7107d21b9b6f4..705fad55ee57e 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageFormat.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing.Imaging { @@ -126,7 +127,7 @@ public static ImageFormat Icon /// Returns a value indicating whether the specified object is an equivalent to this /// . /// - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { ImageFormat? format = o as ImageFormat; if (format == null) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs index 48415cc0b3bfb..39691a9ad5e63 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/Margins.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; @@ -191,7 +192,7 @@ private void CheckMargin(int margin, string name) /// Compares this to a specified to see whether they /// are equal. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is Margins margins)) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs index 51708e341e01a..5bb7a2f9fb03b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs @@ -36,6 +36,7 @@ // using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; namespace System.Drawing @@ -65,7 +66,7 @@ public ToolboxBitmapAttribute(Type t, string name) smallImage = GetImageFromResource(t, name, false); } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (!(value is ToolboxBitmapAttribute)) return false; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs index 417116b2d7078..2cc414e3e184a 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.cs @@ -55,7 +55,7 @@ private ToolboxBitmapAttribute(Image? smallImage, Image? largeImage) _largeImage = largeImage; } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value == this) { diff --git a/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs b/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs index f5153c453ff66..01815dcc9a35d 100644 --- a/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs +++ b/src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs @@ -165,7 +165,7 @@ namespace System.Drawing public static System.Drawing.Color Yellow { get { throw null; } } public static System.Drawing.Color YellowGreen { get { throw null; } } public bool Equals(System.Drawing.Color 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 static System.Drawing.Color FromArgb(int argb) { throw null; } public static System.Drawing.Color FromArgb(int alpha, System.Drawing.Color baseColor) { throw null; } public static System.Drawing.Color FromArgb(int red, int green, int blue) { throw null; } @@ -384,7 +384,7 @@ public partial struct Point : System.IEquatable public static System.Drawing.Point Add(System.Drawing.Point pt, System.Drawing.Size sz) { throw null; } public static System.Drawing.Point Ceiling(System.Drawing.PointF value) { throw null; } public readonly bool Equals(System.Drawing.Point other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public void Offset(System.Drawing.Point p) { } public void Offset(int dx, int dy) { } @@ -411,7 +411,7 @@ public partial struct PointF : System.IEquatable public static System.Drawing.PointF Add(System.Drawing.PointF pt, System.Drawing.Size sz) { throw null; } public static System.Drawing.PointF Add(System.Drawing.PointF pt, System.Drawing.SizeF sz) { throw null; } public readonly bool Equals(System.Drawing.PointF other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Drawing.PointF operator +(System.Drawing.PointF pt, System.Drawing.Size sz) { throw null; } public static System.Drawing.PointF operator +(System.Drawing.PointF pt, System.Drawing.SizeF sz) { throw null; } @@ -453,7 +453,7 @@ public partial struct Rectangle : System.IEquatable public readonly bool Contains(System.Drawing.Rectangle rect) { throw null; } public readonly bool Contains(int x, int y) { throw null; } public readonly bool Equals(System.Drawing.Rectangle other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Drawing.Rectangle FromLTRB(int left, int top, int right, int bottom) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Drawing.Rectangle Inflate(System.Drawing.Rectangle rect, int x, int y) { throw null; } @@ -530,7 +530,7 @@ public partial struct Size : System.IEquatable public static System.Drawing.Size Add(System.Drawing.Size sz1, System.Drawing.Size sz2) { throw null; } public static System.Drawing.Size Ceiling(System.Drawing.SizeF value) { throw null; } public readonly bool Equals(System.Drawing.Size other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Drawing.Size operator +(System.Drawing.Size sz1, System.Drawing.Size sz2) { throw null; } public static System.Drawing.Size operator /(System.Drawing.Size left, int right) { throw null; } @@ -563,7 +563,7 @@ public partial struct SizeF : System.IEquatable public float Width { readonly get { throw null; } set { } } public static System.Drawing.SizeF Add(System.Drawing.SizeF sz1, System.Drawing.SizeF sz2) { throw null; } public readonly bool Equals(System.Drawing.SizeF other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Drawing.SizeF operator +(System.Drawing.SizeF sz1, System.Drawing.SizeF sz2) { throw null; } public static System.Drawing.SizeF operator /(System.Drawing.SizeF left, float right) { throw null; } diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs index 6b63d7932dc43..60a30a32aa130 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace System.Drawing @@ -568,7 +569,7 @@ public override string ToString() public static bool operator !=(Color left, Color right) => !(left == right); - public override bool Equals(object? obj) => obj is Color other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is Color other && Equals(other); public bool Equals(Color other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs index 44c4f6bd3fe65..36c56ce1d0c0b 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -135,7 +136,7 @@ public int Y /// Specifies whether this contains the same coordinates as the specified /// . /// - public override readonly bool Equals(object? obj) => obj is Point && Equals((Point)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is Point && Equals((Point)obj); public readonly bool Equals(Point other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs index 3c112ebe1d643..dbe79a1edb0a3 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -106,7 +107,7 @@ public float Y /// public static PointF Subtract(PointF pt, SizeF sz) => new PointF(pt.X - sz.Width, pt.Y - sz.Height); - public override readonly bool Equals(object? obj) => obj is PointF && Equals((PointF)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is PointF && Equals((PointF)obj); public readonly bool Equals(PointF other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs index 0114f46bd4439..7d728a1fea562 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -155,7 +156,7 @@ public int Height /// Tests whether is a with the same location /// and size of this Rectangle. /// - public override readonly bool Equals(object? obj) => obj is Rectangle && Equals((Rectangle)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is Rectangle && Equals((Rectangle)obj); public readonly bool Equals(Rectangle other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs index 83bbf10c6182e..ea5bdaa396ac6 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -157,7 +158,7 @@ public float Height /// Tests whether is a with the same location and /// size of this . /// - public override readonly bool Equals(object? obj) => obj is RectangleF && Equals((RectangleF)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is RectangleF && Equals((RectangleF)obj); public readonly bool Equals(RectangleF other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs index d7ede97f7b5d9..bd140b7e08019 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -176,7 +177,7 @@ public static Size Round(SizeF value) => /// Tests to see whether the specified object is a with the same dimensions /// as this . /// - public override readonly bool Equals(object? obj) => obj is Size && Equals((Size)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is Size && Equals((Size)obj); public readonly bool Equals(Size other) => this == other; diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs index 36cb96fc9423e..ee86665e47038 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System.Drawing { @@ -137,7 +138,7 @@ public float Height /// Tests to see whether the specified object is a with the same dimensions /// as this . /// - public override readonly bool Equals(object? obj) => obj is SizeF && Equals((SizeF)obj); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => obj is SizeF && Equals((SizeF)obj); public readonly bool Equals(SizeF other) => this == other; diff --git a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs index f3f025610e52f..d649ad56879a8 100644 --- a/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs +++ b/src/libraries/System.Formats.Asn1/ref/System.Formats.Asn1.cs @@ -33,7 +33,7 @@ namespace System.Formats.Asn1 public static System.Formats.Asn1.Asn1Tag Decode(System.ReadOnlySpan source, out int bytesConsumed) { throw null; } public int Encode(System.Span destination) { throw null; } public bool Equals(System.Formats.Asn1.Asn1Tag 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 bool HasSameClassAndValue(System.Formats.Asn1.Asn1Tag other) { throw null; } public static bool operator ==(System.Formats.Asn1.Asn1Tag left, System.Formats.Asn1.Asn1Tag right) { throw null; } diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/Asn1Tag.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/Asn1Tag.cs index 000b7b90d9cbf..691750765e310 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/Asn1Tag.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/Asn1Tag.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Formats.Asn1 { @@ -393,7 +394,7 @@ public bool Equals(Asn1Tag other) /// if is not an , /// otherwise. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is Asn1Tag tag && Equals(tag); } diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnWriter.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnWriter.cs index c5e10fdab20d6..4e48b4bb26a73 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnWriter.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnWriter.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; namespace System.Formats.Asn1 @@ -701,7 +702,7 @@ public bool Equals(StackFrame other) return Tag.Equals(other.Tag) && Offset == other.Offset && ItemType == other.ItemType; } - public override bool Equals(object? obj) => obj is StackFrame other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is StackFrame other && Equals(other); public override int GetHashCode() { diff --git a/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs b/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs index bf467f927d4fa..4f01056d4b12f 100644 --- a/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs +++ b/src/libraries/System.Linq.Expressions/ref/System.Linq.Expressions.cs @@ -32,7 +32,7 @@ public CallInfo(int argCount, System.Collections.Generic.IEnumerable arg public CallInfo(int argCount, params string[] argNames) { } public int ArgumentCount { get { throw null; } } public System.Collections.ObjectModel.ReadOnlyCollection ArgumentNames { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } } public abstract partial class ConvertBinder : System.Dynamic.DynamicMetaObjectBinder diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/BindingRestrictions.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/BindingRestrictions.cs index 97846a853545f..a9b0143babea8 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/BindingRestrictions.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/BindingRestrictions.cs @@ -242,7 +242,7 @@ internal CustomRestriction(Expression expression) _expression = expression; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is CustomRestriction other && other._expression == _expression; } @@ -265,7 +265,7 @@ internal TypeRestriction(Expression parameter, Type type) _type = type; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is TypeRestriction other && other._expression == _expression && TypeUtils.AreEquivalent(other._type, _type); } @@ -287,7 +287,7 @@ internal InstanceRestriction(Expression parameter, object? instance) _instance = instance; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is InstanceRestriction other && other._expression == _expression && other._instance == _instance; } diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/CallInfo.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/CallInfo.cs index bbb6ddaee60af..32948a983cf5c 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/CallInfo.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/CallInfo.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Dynamic.Utils; namespace System.Dynamic @@ -82,7 +83,7 @@ public override int GetHashCode() /// /// The instance of to compare with the current instance. /// true if the specified instance is equal to the current one otherwise, false. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is CallInfo other && ArgumentCount == other.ArgumentCount && ArgumentNames.ListEquals(other.ArgumentNames); } diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/BoundConstants.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/BoundConstants.cs index 54f9671e06c41..e350f29ebdba4 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/BoundConstants.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/BoundConstants.cs @@ -3,9 +3,10 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Dynamic.Utils; using System.Reflection.Emit; using System.Runtime.CompilerServices; -using System.Dynamic.Utils; using static System.Linq.Expressions.CachedReflectionInfo; namespace System.Linq.Expressions.Compiler @@ -42,7 +43,7 @@ public bool Equals(TypedConstant other) { return object.ReferenceEquals(Value, other.Value) && Type.Equals(other.Type); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is TypedConstant typedConstant && Equals(typedConstant); } diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LocalVariables.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LocalVariables.cs index 60c4a4c4c54ae..83177991b77ac 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LocalVariables.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LocalVariables.cs @@ -57,7 +57,7 @@ internal LocalDefinition(int localIndex, ParameterExpression parameter) public int Index { get; } public ParameterExpression Parameter { get; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is LocalDefinition) { diff --git a/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs b/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs index ad36607e44269..4d0266a607cfd 100644 --- a/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs +++ b/src/libraries/System.Memory.Data/ref/System.Memory.Data.cs @@ -13,7 +13,7 @@ public BinaryData(object? jsonSerializable, System.Text.Json.JsonSerializerOptio public BinaryData(System.ReadOnlyMemory data) { } public BinaryData(string data) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public static System.BinaryData FromBytes(byte[] data) { throw null; } public static System.BinaryData FromBytes(System.ReadOnlyMemory data) { throw null; } public static System.BinaryData FromObjectAsJson(T jsonSerializable, System.Text.Json.JsonSerializerOptions? options = null) { throw null; } diff --git a/src/libraries/System.Memory.Data/src/System/BinaryData.cs b/src/libraries/System.Memory.Data/src/System/BinaryData.cs index 8a47558d891e1..8e9744a74c881 100644 --- a/src/libraries/System.Memory.Data/src/System/BinaryData.cs +++ b/src/libraries/System.Memory.Data/src/System/BinaryData.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.InteropServices; using System.Text; @@ -256,7 +257,7 @@ public static implicit operator ReadOnlySpan(BinaryData? data) /// if the specified object is equal to the current object; otherwise, . /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => ReferenceEquals(this, obj); + public override bool Equals([NotNullWhen(true)] object? obj) => ReferenceEquals(this, obj); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/libraries/System.Memory/ref/System.Memory.cs b/src/libraries/System.Memory/ref/System.Memory.cs index 4605336934f94..0cbec39179521 100644 --- a/src/libraries/System.Memory/ref/System.Memory.cs +++ b/src/libraries/System.Memory/ref/System.Memory.cs @@ -146,7 +146,7 @@ public static void Sort(this System.Span keys, Sy private readonly int _dummyPrimitive; public SequencePosition(object? @object, int integer) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.SequencePosition other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } @@ -301,7 +301,7 @@ public void Rewind(long count) { } public byte Precision { get { throw null; } } public char Symbol { get { throw null; } } public bool Equals(System.Buffers.StandardFormat 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 ==(System.Buffers.StandardFormat left, System.Buffers.StandardFormat right) { throw null; } public static implicit operator System.Buffers.StandardFormat (char symbol) { throw null; } diff --git a/src/libraries/System.Memory/src/System/SequencePosition.cs b/src/libraries/System.Memory/src/System/SequencePosition.cs index b3d7649620a01..117131d0ad6d3 100644 --- a/src/libraries/System.Memory/src/System/SequencePosition.cs +++ b/src/libraries/System.Memory/src/System/SequencePosition.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; namespace System { @@ -46,7 +47,7 @@ public SequencePosition(object? @object, int integer) /// equality does not guarantee that they point to the same location in /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) => obj is SequencePosition other && this.Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is SequencePosition other && this.Equals(other); /// [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/libraries/System.Net.Http/ref/System.Net.Http.cs b/src/libraries/System.Net.Http/ref/System.Net.Http.cs index d38fc45156021..c05f0e0e9aead 100644 --- a/src/libraries/System.Net.Http/ref/System.Net.Http.cs +++ b/src/libraries/System.Net.Http/ref/System.Net.Http.cs @@ -216,8 +216,8 @@ public HttpMethod(string method) { } public static System.Net.Http.HttpMethod Post { get { throw null; } } public static System.Net.Http.HttpMethod Put { get { throw null; } } public static System.Net.Http.HttpMethod Trace { get { throw null; } } - public bool Equals(System.Net.Http.HttpMethod? other) { throw null; } - public override bool Equals(object? obj) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] System.Net.Http.HttpMethod? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Net.Http.HttpMethod? left, System.Net.Http.HttpMethod? right) { throw null; } public static bool operator !=(System.Net.Http.HttpMethod? left, System.Net.Http.HttpMethod? right) { throw null; } @@ -434,7 +434,7 @@ public AuthenticationHeaderValue(string scheme) { } public AuthenticationHeaderValue(string scheme, string? parameter) { } public string? Parameter { get { throw null; } } public string Scheme { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.AuthenticationHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -460,7 +460,7 @@ public CacheControlHeaderValue() { } public bool ProxyRevalidate { get { throw null; } set { } } public bool Public { get { throw null; } set { } } public System.TimeSpan? SharedMaxAge { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.CacheControlHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -480,7 +480,7 @@ public ContentDispositionHeaderValue(string dispositionType) { } public System.Collections.Generic.ICollection Parameters { get { throw null; } } public System.DateTimeOffset? ReadDate { get { throw null; } set { } } public long? Size { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.ContentDispositionHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -498,7 +498,7 @@ public ContentRangeHeaderValue(long from, long to, long length) { } public long? Length { get { throw null; } } public long? To { get { throw null; } } public string Unit { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.ContentRangeHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -512,7 +512,7 @@ public EntityTagHeaderValue(string tag, bool isWeak) { } public static System.Net.Http.Headers.EntityTagHeaderValue Any { get { throw null; } } public bool IsWeak { get { throw null; } } public string Tag { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.EntityTagHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -633,7 +633,7 @@ public MediaTypeHeaderValue(string mediaType) { } [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] public string? MediaType { get { throw null; } set { } } public System.Collections.Generic.ICollection Parameters { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.MediaTypeHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -656,7 +656,7 @@ public NameValueHeaderValue(string name) { } public NameValueHeaderValue(string name, string? value) { } public string Name { get { throw null; } } public string? Value { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.NameValueHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -669,7 +669,7 @@ protected NameValueWithParametersHeaderValue(System.Net.Http.Headers.NameValueWi public NameValueWithParametersHeaderValue(string name) : base (default(string)) { } public NameValueWithParametersHeaderValue(string name, string? value) : base (default(string)) { } public System.Collections.Generic.ICollection Parameters { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static new System.Net.Http.Headers.NameValueWithParametersHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -682,7 +682,7 @@ public ProductHeaderValue(string name) { } public ProductHeaderValue(string name, string? version) { } public string Name { get { throw null; } } public string? Version { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.ProductHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -696,7 +696,7 @@ public ProductInfoHeaderValue(string comment) { } public ProductInfoHeaderValue(string productName, string? productVersion) { } public string? Comment { get { throw null; } } public System.Net.Http.Headers.ProductHeaderValue? Product { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.ProductInfoHeaderValue Parse(string input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -710,7 +710,7 @@ public RangeConditionHeaderValue(System.Net.Http.Headers.EntityTagHeaderValue en public RangeConditionHeaderValue(string entityTag) { } public System.DateTimeOffset? Date { get { throw null; } } public System.Net.Http.Headers.EntityTagHeaderValue? EntityTag { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.RangeConditionHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -723,7 +723,7 @@ public RangeHeaderValue() { } public RangeHeaderValue(long? from, long? to) { } public System.Collections.Generic.ICollection Ranges { get { throw null; } } public string Unit { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.RangeHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -735,7 +735,7 @@ public partial class RangeItemHeaderValue : System.ICloneable public RangeItemHeaderValue(long? from, long? to) { } public long? From { get { throw null; } } public long? To { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } object System.ICloneable.Clone() { throw null; } public override string ToString() { throw null; } @@ -746,7 +746,7 @@ public RetryConditionHeaderValue(System.DateTimeOffset date) { } public RetryConditionHeaderValue(System.TimeSpan delta) { } public System.DateTimeOffset? Date { get { throw null; } } public System.TimeSpan? Delta { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.RetryConditionHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -759,7 +759,7 @@ public StringWithQualityHeaderValue(string value) { } public StringWithQualityHeaderValue(string value, double quality) { } public double? Quality { get { throw null; } } public string Value { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.StringWithQualityHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -772,7 +772,7 @@ protected TransferCodingHeaderValue(System.Net.Http.Headers.TransferCodingHeader public TransferCodingHeaderValue(string value) { } public System.Collections.Generic.ICollection Parameters { get { throw null; } } public string Value { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.TransferCodingHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -797,7 +797,7 @@ public ViaHeaderValue(string protocolVersion, string receivedBy, string? protoco public string? ProtocolName { get { throw null; } } public string ProtocolVersion { get { throw null; } } public string ReceivedBy { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.ViaHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } @@ -812,7 +812,7 @@ public WarningHeaderValue(int code, string agent, string text, System.DateTimeOf public int Code { get { throw null; } } public System.DateTimeOffset? Date { get { throw null; } } public string Text { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.Http.Headers.WarningHeaderValue Parse(string? input) { throw null; } object System.ICloneable.Clone() { throw null; } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs index 4b1c413232582..2b6538028e17b 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/AuthenticationHeaderValue.cs @@ -59,7 +59,7 @@ public override string ToString() return _scheme + " " + _parameter; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { AuthenticationHeaderValue? other = obj as AuthenticationHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ByteArrayHeaderParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ByteArrayHeaderParser.cs index 476e4b425b9c8..b5631b2253c8d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ByteArrayHeaderParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ByteArrayHeaderParser.cs @@ -24,7 +24,7 @@ public override string ToString(object value) return Convert.ToBase64String((byte[])value); } - public override bool TryParseValue(string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) + public override bool TryParseValue([NotNullWhen(true)] string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) { parsedValue = null; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderValue.cs index e51a5c56d2f4c..55c966d1eaa54 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/CacheControlHeaderValue.cs @@ -285,7 +285,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { CacheControlHeaderValue? other = obj as CacheControlHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentDispositionHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentDispositionHeaderValue.cs index d58feb4a2e262..079b8a5b2e754 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentDispositionHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentDispositionHeaderValue.cs @@ -162,7 +162,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { ContentDispositionHeaderValue? other = obj as ContentDispositionHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentRangeHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentRangeHeaderValue.cs index ef5c13729ac24..c9aab0f9346c4 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentRangeHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ContentRangeHeaderValue.cs @@ -119,7 +119,7 @@ private ContentRangeHeaderValue(ContentRangeHeaderValue source) _unit = source._unit; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { ContentRangeHeaderValue? other = obj as ContentRangeHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/DateHeaderParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/DateHeaderParser.cs index 993588a82c486..cfa45a84d38ad 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/DateHeaderParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/DateHeaderParser.cs @@ -24,7 +24,7 @@ public override string ToString(object value) return HttpDateParser.DateToString((DateTimeOffset)value); } - public override bool TryParseValue(string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) + public override bool TryParseValue([NotNullWhen(true)] string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) { parsedValue = null; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/EntityTagHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/EntityTagHeaderValue.cs index 964001e767646..7725c0031861c 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/EntityTagHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/EntityTagHeaderValue.cs @@ -69,7 +69,7 @@ public override string ToString() return _tag; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { EntityTagHeaderValue? other = obj as EntityTagHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/MediaTypeHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/MediaTypeHeaderValue.cs index 4fe5d1c3fbd3d..4a486c5b71460 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/MediaTypeHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/MediaTypeHeaderValue.cs @@ -105,7 +105,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { MediaTypeHeaderValue? other = obj as MediaTypeHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueHeaderValue.cs index ccda2cb76f3bc..fd93678d939e8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueHeaderValue.cs @@ -80,7 +80,7 @@ public override int GetHashCode() return nameHashCode; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { NameValueHeaderValue? other = obj as NameValueHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueWithParametersHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueWithParametersHeaderValue.cs index e5fefd53fe807..7ab592cd9f78d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueWithParametersHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/NameValueWithParametersHeaderValue.cs @@ -45,7 +45,7 @@ protected NameValueWithParametersHeaderValue(NameValueWithParametersHeaderValue } } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { bool result = base.Equals(obj); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductHeaderValue.cs index b0f74823f2f78..555b1eb1a73c0 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductHeaderValue.cs @@ -57,7 +57,7 @@ public override string ToString() return _name + "/" + _version; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { ProductHeaderValue? other = obj as ProductHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderParser.cs index 1193b555c96de..b0a17a4620c48 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderParser.cs @@ -21,7 +21,7 @@ private ProductInfoHeaderParser(bool supportsMultipleValues) { } - public override bool TryParseValue(string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) + public override bool TryParseValue([NotNullWhen(true)] string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) { parsedValue = null; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderValue.cs index 80f8639c3f804..d04ac66156903 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ProductInfoHeaderValue.cs @@ -60,7 +60,7 @@ public override string ToString() return _product.ToString(); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { ProductInfoHeaderValue? other = obj as ProductInfoHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeConditionHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeConditionHeaderValue.cs index 423a9c7e7e48f..65677caac1d6d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeConditionHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeConditionHeaderValue.cs @@ -59,7 +59,7 @@ public override string ToString() return _entityTag.ToString(); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { RangeConditionHeaderValue? other = obj as RangeConditionHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeHeaderValue.cs index a1ba30e4c693a..503f54db13f4f 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeHeaderValue.cs @@ -81,7 +81,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { RangeHeaderValue? other = obj as RangeHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeItemHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeItemHeaderValue.cs index 5cc5f5c44c725..68197f0f7d8ce 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeItemHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RangeItemHeaderValue.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace System.Net.Http.Headers @@ -68,7 +69,7 @@ public override string ToString() _to.Value.ToString(NumberFormatInfo.InvariantInfo); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { RangeItemHeaderValue? other = obj as RangeItemHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RetryConditionHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RetryConditionHeaderValue.cs index cf4fbe9598ee9..5343cb23bc502 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RetryConditionHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/RetryConditionHeaderValue.cs @@ -56,7 +56,7 @@ public override string ToString() return HttpDateParser.DateToString(_date.Value); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { RetryConditionHeaderValue? other = obj as RetryConditionHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/StringWithQualityHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/StringWithQualityHeaderValue.cs index e5841bf2a0928..814a053f5ad61 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/StringWithQualityHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/StringWithQualityHeaderValue.cs @@ -60,7 +60,7 @@ public override string ToString() return _value; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { StringWithQualityHeaderValue? other = obj as StringWithQualityHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/TransferCodingHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/TransferCodingHeaderValue.cs index 7e767d877d0cd..cbcc18caa980a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/TransferCodingHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/TransferCodingHeaderValue.cs @@ -127,7 +127,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { TransferCodingHeaderValue? other = obj as TransferCodingHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/UriHeaderParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/UriHeaderParser.cs index b0d6f094da426..37c71f52accbe 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/UriHeaderParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/UriHeaderParser.cs @@ -22,7 +22,7 @@ private UriHeaderParser(UriKind uriKind) _uriKind = uriKind; } - public override bool TryParseValue(string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) + public override bool TryParseValue([NotNullWhen(true)] string? value, object? storeValue, ref int index, [NotNullWhen(true)] out object? parsedValue) { parsedValue = null; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ViaHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ViaHeaderValue.cs index 6f6e891cde26e..6f7ebdd49482e 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ViaHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/ViaHeaderValue.cs @@ -99,7 +99,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { ViaHeaderValue? other = obj as ViaHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/WarningHeaderValue.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/WarningHeaderValue.cs index 81eb0feda0e43..c232ba8371df8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/WarningHeaderValue.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/WarningHeaderValue.cs @@ -91,7 +91,7 @@ public override string ToString() return StringBuilderCache.GetStringAndRelease(sb); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { WarningHeaderValue? other = obj as WarningHeaderValue; diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs index 270d76a1cb40e..37322cbbc3d57 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Net.Http.QPack; namespace System.Net.Http @@ -105,7 +106,7 @@ private HttpMethod(string method, int? http3StaticTableIndex) #region IEquatable Members - public bool Equals(HttpMethod? other) + public bool Equals([NotNullWhen(true)] HttpMethod? other) { if (other is null) { @@ -124,7 +125,7 @@ public bool Equals(HttpMethod? other) #endregion - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as HttpMethod); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpAuthority.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpAuthority.cs index 43a4181aa60c0..31e181ac09ee8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpAuthority.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpAuthority.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Net.Http { @@ -29,12 +30,12 @@ public HttpAuthority(string host, int port) Port = port; } - public bool Equals(HttpAuthority? other) + public bool Equals([NotNullWhen(true)] HttpAuthority? other) { return other != null && string.Equals(IdnHost, other.IdnHost) && Port == other.Port; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is HttpAuthority other && Equals(other); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs index 753c672fa28e2..fd03e3d5c68c4 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Net.Http.Headers; @@ -1949,7 +1950,7 @@ public bool IsUsable( } public bool Equals(CachedConnection other) => ReferenceEquals(other._connection, _connection); - public override bool Equals(object? obj) => obj is CachedConnection && Equals((CachedConnection)obj); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is CachedConnection && Equals((CachedConnection)obj); public override int GetHashCode() => _connection?.GetHashCode() ?? 0; } } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs index 84ac7270df15c..c7f70725895ec 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; @@ -537,7 +538,7 @@ public override int GetHashCode() => HashCode.Combine(Kind, Host, Port, ProxyUri, Identity) : HashCode.Combine(Kind, Host, Port, SslHostName, ProxyUri, Identity)); - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is HttpConnectionKey hck && Equals(hck); diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ListenerPrefix.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ListenerPrefix.cs index 172877a401978..b95e58287235e 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ListenerPrefix.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Managed/ListenerPrefix.cs @@ -30,6 +30,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +using System.Diagnostics.CodeAnalysis; + namespace System.Net { internal sealed class ListenerPrefix @@ -79,7 +81,7 @@ public string? Path } // Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection. - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { ListenerPrefix? other = o as ListenerPrefix; if (other == null) diff --git a/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs b/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs index 5826634dd14a9..724e6bf5b8efb 100644 --- a/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs +++ b/src/libraries/System.Net.Mail/ref/System.Net.Mail.cs @@ -110,7 +110,7 @@ public MailAddress(string address, string? displayName, System.Text.Encoding? di public string DisplayName { get { throw null; } } public string Host { get { throw null; } } public string User { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public static bool TryCreate(string address, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out MailAddress? result) { throw null; } public static bool TryCreate(string address, string? displayName, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out MailAddress? result) { throw null; } @@ -288,7 +288,7 @@ public ContentDisposition(string disposition) { } public System.Collections.Specialized.StringDictionary Parameters { get { throw null; } } public System.DateTime ReadDate { get { throw null; } set { } } public long Size { get { throw null; } set { } } - public override bool Equals(object? rparam) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? rparam) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -302,7 +302,7 @@ public ContentType(string contentType) { } [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string Name { get { throw null; } set { } } public System.Collections.Specialized.StringDictionary Parameters { get { throw null; } } - public override bool Equals(object? rparam) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? rparam) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs index 9c076fa0106f6..9b4a06dd0a71b 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddress.cs @@ -261,7 +261,7 @@ public override string ToString() } } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value == null) { diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs index 9be879b83eaed..b3ca5f87ac509 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentDisposition.cs @@ -250,7 +250,7 @@ private static void EncodeToBuffer(string value, StringBuilder builder, bool all } } - public override bool Equals(object? rparam) + public override bool Equals([NotNullWhen(true)] object? rparam) { return rparam == null ? false : diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs index 7c09183ebe8de..5595f7aab2228 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mime/ContentType.cs @@ -224,7 +224,7 @@ private static void EncodeToBuffer(string value, StringBuilder builder, bool all } } - public override bool Equals(object? rparam) => + public override bool Equals([NotNullWhen(true)] object? rparam) => rparam == null ? false : string.Equals(ToString(), rparam.ToString(), StringComparison.OrdinalIgnoreCase); public override int GetHashCode() => ToString().ToLowerInvariant().GetHashCode(); diff --git a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs index 95778697740f0..3a58ffe13bcb3 100644 --- a/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs +++ b/src/libraries/System.Net.NetworkInformation/ref/System.Net.NetworkInformation.cs @@ -365,7 +365,7 @@ public partial class PhysicalAddress { public static readonly System.Net.NetworkInformation.PhysicalAddress None; public PhysicalAddress(byte[] address) { } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public byte[] GetAddressBytes() { throw null; } public override int GetHashCode() { throw null; } public static System.Net.NetworkInformation.PhysicalAddress Parse(string? address) { throw null; } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs index 7a238f72c4337..ad3fcd9caad0d 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/PhysicalAddress.cs @@ -57,7 +57,7 @@ public override int GetHashCode() return _hash; } - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { PhysicalAddress? address = comparand as PhysicalAddress; if (address == null) diff --git a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs index c784dd7353ae3..398048f942cab 100644 --- a/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs +++ b/src/libraries/System.Net.Primitives/ref/System.Net.Primitives.cs @@ -43,7 +43,7 @@ public Cookie(string name, string? value, string? path, string? domain) { } [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string Value { get { throw null; } set { } } public int Version { get { throw null; } set { } } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -122,7 +122,7 @@ public DnsEndPoint(string host, int port, System.Net.Sockets.AddressFamily addre public override System.Net.Sockets.AddressFamily AddressFamily { get { throw null; } } public string Host { get { throw null; } } public int Port { get { throw null; } } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -241,7 +241,7 @@ public IPAddress(System.ReadOnlySpan address, long scopeid) { } public bool IsIPv6SiteLocal { get { throw null; } } public bool IsIPv6Teredo { get { throw null; } } public long ScopeId { get { throw null; } set { } } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public byte[] GetAddressBytes() { throw null; } public override int GetHashCode() { throw null; } public static short HostToNetworkOrder(short host) { throw null; } @@ -271,7 +271,7 @@ public IPEndPoint(System.Net.IPAddress address, int port) { } public override System.Net.Sockets.AddressFamily AddressFamily { get { throw null; } } public int Port { get { throw null; } set { } } public override System.Net.EndPoint Create(System.Net.SocketAddress socketAddress) { throw null; } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public override int GetHashCode() { throw null; } public static System.Net.IPEndPoint Parse(System.ReadOnlySpan s) { throw null; } public static System.Net.IPEndPoint Parse(string s) { throw null; } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs index dc694bc09ecde..33992d599dbb3 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/Cookie.cs @@ -710,7 +710,7 @@ public int Version } } - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { Cookie? other = comparand as Cookie; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/CredentialCache.cs b/src/libraries/System.Net.Primitives/src/System/Net/CredentialCache.cs index ff3f6af142296..212e3b6e0941f 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/CredentialCache.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/CredentialCache.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; namespace System.Net @@ -447,7 +448,7 @@ public bool Equals(CredentialHostKey other) return equals; } - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is CredentialHostKey && Equals((CredentialHostKey)obj); public override string ToString() => @@ -523,7 +524,7 @@ public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(AuthenticationType) ^ UriPrefix.GetHashCode(); - public bool Equals(CredentialKey? other) + public bool Equals([NotNullWhen(true)] CredentialKey? other) { if (other == null) { @@ -539,7 +540,7 @@ public bool Equals(CredentialKey? other) return equals; } - public override bool Equals(object? obj) => Equals(obj as CredentialKey); + public override bool Equals([NotNullWhen(true)] object? obj) => Equals(obj as CredentialKey); public override string ToString() => "[" + UriPrefixLength.ToString(NumberFormatInfo.InvariantInfo) + "]:" + UriPrefix + ":" + AuthenticationType; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/DnsEndPoint.cs b/src/libraries/System.Net.Primitives/src/System/Net/DnsEndPoint.cs index 0fb78438f5dc8..fc6fb3b9177bb 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/DnsEndPoint.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/DnsEndPoint.cs @@ -1,6 +1,7 @@ // 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; using System.Net.Sockets; namespace System.Net @@ -42,7 +43,7 @@ public DnsEndPoint(string host, int port, AddressFamily addressFamily) _family = addressFamily; } - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { DnsEndPoint? dnsComparand = comparand as DnsEndPoint; diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs index c2b7ec3757bbf..4763d5203075e 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPAddress.cs @@ -546,7 +546,7 @@ public long Address } /// Compares two IP addresses. - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { return comparand is IPAddress address && Equals(address); } diff --git a/src/libraries/System.Net.Primitives/src/System/Net/IPEndPoint.cs b/src/libraries/System.Net.Primitives/src/System/Net/IPEndPoint.cs index 921f22af6db04..edc8ff2820a6b 100644 --- a/src/libraries/System.Net.Primitives/src/System/Net/IPEndPoint.cs +++ b/src/libraries/System.Net.Primitives/src/System/Net/IPEndPoint.cs @@ -174,7 +174,7 @@ public override EndPoint Create(SocketAddress socketAddress) return socketAddress.GetIPEndPoint(); } - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { return comparand is IPEndPoint other && other._address.Equals(_address) && other._port == _port; } diff --git a/src/libraries/System.Net.Security/ref/System.Net.Security.cs b/src/libraries/System.Net.Security/ref/System.Net.Security.cs index 9092eb24326eb..ab478a68272a8 100644 --- a/src/libraries/System.Net.Security/ref/System.Net.Security.cs +++ b/src/libraries/System.Net.Security/ref/System.Net.Security.cs @@ -123,7 +123,7 @@ public readonly struct SslClientHelloInfo public SslApplicationProtocol(string protocol) { throw null; } public System.ReadOnlyMemory Protocol { get { throw null; } } public bool Equals(System.Net.Security.SslApplicationProtocol other) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Net.Security.SslApplicationProtocol left, System.Net.Security.SslApplicationProtocol right) { throw null; } public static bool operator !=(System.Net.Security.SslApplicationProtocol left, System.Net.Security.SslApplicationProtocol right) { throw null; } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslApplicationProtocol.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslApplicationProtocol.cs index 6b1a912588065..0a93645ac000f 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslApplicationProtocol.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslApplicationProtocol.cs @@ -3,6 +3,7 @@ #nullable enable using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text; namespace System.Net.Security @@ -51,7 +52,7 @@ public SslApplicationProtocol(string protocol) : public bool Equals(SslApplicationProtocol other) => ((ReadOnlySpan)_readOnlyProtocol).SequenceEqual(other._readOnlyProtocol); - public override bool Equals(object? obj) => obj is SslApplicationProtocol protocol && Equals(protocol); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is SslApplicationProtocol protocol && Equals(protocol); public override int GetHashCode() { diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs index 3aa020bd4dae2..13e4f772f6b3b 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslSessionsCache.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Security.Authentication; namespace System.Net.Security @@ -68,7 +69,7 @@ public override int GetHashCode() return hashCode; } - public override bool Equals(object? obj) => (obj is SslCredKey && Equals((SslCredKey)obj)); + public override bool Equals([NotNullWhen(true)] object? obj) => (obj is SslCredKey && Equals((SslCredKey)obj)); public bool Equals(SslCredKey other) { diff --git a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs index 4a909e43a4630..4f99d1eaff78b 100644 --- a/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs +++ b/src/libraries/System.Net.Sockets/ref/System.Net.Sockets.cs @@ -80,7 +80,7 @@ public partial struct IPPacketInformation private int _dummyPrimitive; public System.Net.IPAddress Address { get { throw null; } } public int Interface { get { throw null; } } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Net.Sockets.IPPacketInformation packetInformation1, System.Net.Sockets.IPPacketInformation packetInformation2) { throw null; } public static bool operator !=(System.Net.Sockets.IPPacketInformation packetInformation1, System.Net.Sockets.IPPacketInformation packetInformation2) { throw null; } @@ -759,7 +759,7 @@ public partial struct UdpReceiveResult : System.IEquatable + public override bool Equals([NotNullWhen(true)] object? comparand) => comparand is IPPacketInformation other && this == other; public override int GetHashCode() diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs index 54e176758caa8..25af4a45bbaa1 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UdpReceiveResult.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 System.Net.Sockets { /// @@ -68,7 +70,7 @@ public override int GetHashCode() /// /// The object to compare with this instance /// true if obj is an instance of and equals the value of the instance; otherwise, false - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is UdpReceiveResult other && Equals(other); /// diff --git a/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs b/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs index 7e293b8fce233..a594fa5302c6d 100644 --- a/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs +++ b/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs @@ -32,7 +32,7 @@ public partial struct Matrix3x2 : System.IEquatable public static System.Numerics.Matrix3x2 CreateTranslation(System.Numerics.Vector2 position) { throw null; } public static System.Numerics.Matrix3x2 CreateTranslation(float xPosition, float yPosition) { throw null; } public readonly bool Equals(System.Numerics.Matrix3x2 other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public readonly float GetDeterminant() { throw null; } public override readonly int GetHashCode() { throw null; } public static bool Invert(System.Numerics.Matrix3x2 matrix, out System.Numerics.Matrix3x2 result) { throw null; } @@ -104,7 +104,7 @@ public partial struct Matrix4x4 : System.IEquatable public static System.Numerics.Matrix4x4 CreateWorld(System.Numerics.Vector3 position, System.Numerics.Vector3 forward, System.Numerics.Vector3 up) { throw null; } public static bool Decompose(System.Numerics.Matrix4x4 matrix, out System.Numerics.Vector3 scale, out System.Numerics.Quaternion rotation, out System.Numerics.Vector3 translation) { throw null; } public readonly bool Equals(System.Numerics.Matrix4x4 other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public readonly float GetDeterminant() { throw null; } public override readonly int GetHashCode() { throw null; } public static bool Invert(System.Numerics.Matrix4x4 matrix, out System.Numerics.Matrix4x4 result) { throw null; } @@ -136,7 +136,7 @@ public partial struct Plane : System.IEquatable public static float DotCoordinate(System.Numerics.Plane plane, System.Numerics.Vector3 value) { throw null; } public static float DotNormal(System.Numerics.Plane plane, System.Numerics.Vector3 value) { throw null; } public readonly bool Equals(System.Numerics.Plane other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Numerics.Plane Normalize(System.Numerics.Plane value) { throw null; } public static bool operator ==(System.Numerics.Plane value1, System.Numerics.Plane value2) { throw null; } @@ -164,7 +164,7 @@ public partial struct Quaternion : System.IEquatable public static System.Numerics.Quaternion Divide(System.Numerics.Quaternion value1, System.Numerics.Quaternion value2) { throw null; } public static float Dot(System.Numerics.Quaternion quaternion1, System.Numerics.Quaternion quaternion2) { throw null; } public readonly bool Equals(System.Numerics.Quaternion other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Numerics.Quaternion Inverse(System.Numerics.Quaternion value) { throw null; } public readonly float Length() { throw null; } @@ -318,7 +318,7 @@ public readonly void CopyTo(float[] array, int index) { } public static System.Numerics.Vector2 Divide(System.Numerics.Vector2 left, float divisor) { throw null; } public static float Dot(System.Numerics.Vector2 value1, System.Numerics.Vector2 value2) { throw null; } public readonly bool Equals(System.Numerics.Vector2 other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public readonly float Length() { throw null; } public readonly float LengthSquared() { throw null; } @@ -377,7 +377,7 @@ public readonly void CopyTo(float[] array, int index) { } public static System.Numerics.Vector3 Divide(System.Numerics.Vector3 left, float divisor) { throw null; } public static float Dot(System.Numerics.Vector3 vector1, System.Numerics.Vector3 vector2) { throw null; } public readonly bool Equals(System.Numerics.Vector3 other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public readonly float Length() { throw null; } public readonly float LengthSquared() { throw null; } @@ -436,7 +436,7 @@ public readonly void CopyTo(float[] array, int index) { } public static System.Numerics.Vector4 Divide(System.Numerics.Vector4 left, float divisor) { throw null; } public static float Dot(System.Numerics.Vector4 vector1, System.Numerics.Vector4 vector2) { throw null; } public readonly bool Equals(System.Numerics.Vector4 other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public readonly float Length() { throw null; } public readonly float LengthSquared() { throw null; } @@ -488,7 +488,7 @@ public readonly void CopyTo(System.Span destination) { } public readonly void CopyTo(T[] destination) { } public readonly void CopyTo(T[] destination, int startIndex) { } public readonly bool Equals(System.Numerics.Vector other) { throw null; } - public override readonly bool Equals(object? obj) { throw null; } + public override readonly bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override readonly int GetHashCode() { throw null; } public static System.Numerics.Vector operator +(System.Numerics.Vector left, System.Numerics.Vector right) { throw null; } public static System.Numerics.Vector operator &(System.Numerics.Vector left, System.Numerics.Vector right) { throw null; } diff --git a/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs b/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs index 2358820a73331..744576e587d06 100644 --- a/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs +++ b/src/libraries/System.ObjectModel/ref/System.ObjectModel.cs @@ -202,7 +202,7 @@ public TypeConverterAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccess public TypeConverterAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type) { } [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public string ConverterTypeName { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } } [System.AttributeUsageAttribute(System.AttributeTargets.Class, Inherited=true)] diff --git a/src/libraries/System.ObjectModel/src/System/ComponentModel/TypeConverterAttribute.cs b/src/libraries/System.ObjectModel/src/System/ComponentModel/TypeConverterAttribute.cs index df6569a283a73..36fa3052c73f5 100644 --- a/src/libraries/System.ObjectModel/src/System/ComponentModel/TypeConverterAttribute.cs +++ b/src/libraries/System.ObjectModel/src/System/ComponentModel/TypeConverterAttribute.cs @@ -64,7 +64,7 @@ public TypeConverterAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMem [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public string ConverterTypeName { get; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is TypeConverterAttribute other && diff --git a/src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs b/src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs index af258f6afb903..30542d17ece7f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ApplicationId.cs @@ -1,6 +1,7 @@ // 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; using System.Text; namespace System @@ -71,7 +72,7 @@ private static void EncodeHexString(byte[] sArray, ref ValueStringBuilder string } } - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { ApplicationId? other = o as ApplicationId; if (other == null) diff --git a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs index 6355847a87f49..f2acaca5d0dbe 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ArraySegment.cs @@ -15,6 +15,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System { @@ -118,7 +119,7 @@ public void CopyTo(ArraySegment destination) System.Array.Copy(_array!, _offset, destination._array!, destination._offset, _count); } - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is ArraySegment && Equals((ArraySegment)obj); public bool Equals(ArraySegment obj) => diff --git a/src/libraries/System.Private.CoreLib/src/System/Attribute.cs b/src/libraries/System.Private.CoreLib/src/System/Attribute.cs index 5ff290be6be26..27ff2091d82b4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Attribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Attribute.cs @@ -17,7 +17,7 @@ protected Attribute() { } #if !CORERT [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", Justification = "Unused fields don't make a difference for equality")] - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null) return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/Boolean.cs b/src/libraries/System.Private.CoreLib/src/System/Boolean.cs index 1f33ae5d2b419..b9eb80e59db0e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Boolean.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Boolean.cs @@ -126,7 +126,7 @@ public bool TryFormat(Span destination, out int charsWritten) } // Determines whether two Boolean objects are equal. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { // If it's not a boolean, we're definitely not equal if (!(obj is bool)) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/StandardFormat.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/StandardFormat.cs index 46f0847405341..0f2bf8a75004b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/StandardFormat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/StandardFormat.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Buffers { @@ -128,7 +129,7 @@ private static bool ParseHelper(ReadOnlySpan format, out StandardFormat st /// /// Returns true if both the Symbol and Precision are equal. /// - public override bool Equals(object? obj) => obj is StandardFormat other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is StandardFormat other && Equals(other); /// /// Compute a hash code. diff --git a/src/libraries/System.Private.CoreLib/src/System/Byte.cs b/src/libraries/System.Private.CoreLib/src/System/Byte.cs index 1fdebb7e84e80..4499bbd14a9f0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Byte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Byte.cs @@ -49,7 +49,7 @@ public int CompareTo(byte value) } // Determines whether two Byte objects are equal. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is byte)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Char.cs b/src/libraries/System.Private.CoreLib/src/System/Char.cs index e95cc10cb2d73..28670f8037226 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Char.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Char.cs @@ -105,7 +105,7 @@ public override int GetHashCode() // Used for comparing two boxed Char objects. // - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is char)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs index 2ee414aa62791..f022ee27b1b09 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Comparer.cs @@ -67,7 +67,7 @@ public override int Compare(T? x, T? y) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -91,7 +91,7 @@ public override int Compare(T? x, T? y) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -109,7 +109,7 @@ public override int Compare(T? x, T? y) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -127,7 +127,7 @@ private EnumComparer(SerializationInfo info, StreamingContext context) { } // public override int Compare(T x, T y) is runtime-specific // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs index a475c37225121..0af18e7f7dd1a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/EqualityComparer.cs @@ -86,7 +86,7 @@ public override bool Equals(T? x, T? y) // Equals method for the comparer itself. // If in the future this type is made sealed, change the is check to obj != null && GetType() == obj.GetType(). - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is GenericEqualityComparer; // If in the future this type is made sealed, change typeof(...) to GetType(). @@ -115,7 +115,7 @@ public override bool Equals(T? x, T? y) public override int GetHashCode(T? obj) => obj.GetHashCode(); // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -143,7 +143,7 @@ public override bool Equals(T? x, T? y) public override int GetHashCode([DisallowNull] T obj) => obj?.GetHashCode() ?? 0; // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -168,7 +168,7 @@ public override int GetHashCode(byte b) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => @@ -203,7 +203,7 @@ public override int GetHashCode(T obj) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj != null && GetType() == obj.GetType(); public override int GetHashCode() => diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSetEqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSetEqualityComparer.cs index 37466e5fb4c0c..bd741f8ab1381 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSetEqualityComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/HashSetEqualityComparer.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 System.Collections.Generic { /// Equality comparer for hashsets of hashsets @@ -70,7 +72,7 @@ public int GetHashCode(HashSet? obj) } // Equals method for the comparer itself. - public override bool Equals(object? obj) => obj is HashSetEqualityComparer; + public override bool Equals([NotNullWhen(true)] object? obj) => obj is HashSetEqualityComparer; public override int GetHashCode() => EqualityComparer.Default.GetHashCode(); } diff --git a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs index 1d96a8bb75ece..3a09e36f29c3c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/DefaultValueAttribute.cs @@ -226,7 +226,7 @@ public DefaultValueAttribute(ulong value) /// public virtual object? Value => _value; - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == this) { diff --git a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/EditorBrowsableAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/EditorBrowsableAttribute.cs index c7f8561c7b6ef..ccc18733cf070 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ComponentModel/EditorBrowsableAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ComponentModel/EditorBrowsableAttribute.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 System.ComponentModel { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate | AttributeTargets.Interface)] @@ -17,7 +19,7 @@ public EditorBrowsableAttribute() : this(EditorBrowsableState.Always) public EditorBrowsableState State { get; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == this) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Convert.cs b/src/libraries/System.Private.CoreLib/src/System/Convert.cs index 6f2e89d7f6965..05384d5449a35 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Convert.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Convert.cs @@ -378,12 +378,12 @@ internal static object DefaultToType(IConvertible value, Type targetType, IForma private static void ThrowUInt64OverflowException() { throw new OverflowException(SR.Overflow_UInt64); } // Conversions to Boolean - public static bool ToBoolean(object? value) + public static bool ToBoolean([NotNullWhen(true)] object? value) { return value == null ? false : ((IConvertible)value).ToBoolean(null); } - public static bool ToBoolean(object? value, IFormatProvider? provider) + public static bool ToBoolean([NotNullWhen(true)] object? value, IFormatProvider? provider) { return value == null ? false : ((IConvertible)value).ToBoolean(provider); } @@ -444,14 +444,14 @@ public static bool ToBoolean(ulong value) return value != 0; } - public static bool ToBoolean(string? value) + public static bool ToBoolean([NotNullWhen(true)] string? value) { if (value == null) return false; return bool.Parse(value); } - public static bool ToBoolean(string? value, IFormatProvider? provider) + public static bool ToBoolean([NotNullWhen(true)] string? value, IFormatProvider? provider) { if (value == null) return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs index f45333cbad1cf..6354382405dbf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs @@ -695,7 +695,7 @@ internal static long DoubleDateToTicks(double value) // is equal to the value of this DateTime. Returns false // otherwise. // - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is DateTime) { diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs index 0ba7aaac6a4f1..703fd27ce86a2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTimeOffset.cs @@ -387,7 +387,7 @@ public int CompareTo(DateTimeOffset other) // is equal to the value of this DateTimeOffset. Returns false // otherwise. // - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is DateTimeOffset && UtcDateTime.Equals(((DateTimeOffset)obj).UtcDateTime); public bool Equals(DateTimeOffset other) => diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index 97e620e68f0a7..04fffff08ce68 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -394,7 +394,7 @@ public static decimal Divide(decimal d1, decimal d2) // if the given object is a boxed Decimal and its value is equal to the // value of this Decimal. Returns false otherwise. // - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is decimal other && DecCalc.VarDecCmp(in this, in other) == 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs index 5bdde239895ad..c3994e613a316 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventDescriptor.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; #if ES_BUILD_STANDALONE @@ -103,7 +104,7 @@ long keywords internal int TraceLoggingId => m_traceloggingId; - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is EventDescriptor ed && Equals(ed); public override int GetHashCode() => diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 2aba7894f4e84..912d19e1d7222 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -197,7 +197,7 @@ public int CompareTo(double value) // True if obj is another Double with the same value as the current instance. This is // a method of object equality, that only returns true if obj is also a double. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is double)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Enum.cs b/src/libraries/System.Private.CoreLib/src/System/Enum.cs index e8377f593bb7d..3eddcd4a5d03a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Enum.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Enum.cs @@ -464,10 +464,10 @@ private static bool TryParse(Type enumType, string? value, bool ignoreCase, bool } } - public static bool TryParse(string? value, out TEnum result) where TEnum : struct => + public static bool TryParse([NotNullWhen(true)] string? value, out TEnum result) where TEnum : struct => TryParse(value, ignoreCase: false, out result); - public static bool TryParse(string? value, bool ignoreCase, out TEnum result) where TEnum : struct => + public static bool TryParse([NotNullWhen(true)] string? value, bool ignoreCase, out TEnum result) where TEnum : struct => TryParse(value, ignoreCase, throwOnFailure: false, out result); private static bool TryParse(string? value, bool ignoreCase, bool throwOnFailure, out TEnum result) where TEnum : struct diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs index 148daeb0aed62..3f35e96a69ea0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.cs @@ -1516,7 +1516,7 @@ private int GetSortKeyLengthCore(ReadOnlySpan source, CompareOptions optio NlsGetSortKeyLength(source, options) : IcuGetSortKeyLength(source, options); - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { return value is CompareInfo otherCompareInfo && Name == otherCompareInfo.Name; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs index 5a071799bbb05..311d9b955ead0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureInfo.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Threading; namespace System.Globalization @@ -656,7 +657,7 @@ public virtual TextInfo TextInfo } } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (object.ReferenceEquals(this, value)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs index e0b9e8251f602..81b20d53e55a4 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/IdnMapping.cs @@ -24,6 +24,7 @@ // RFC 3492 - Punycode: A Bootstring encoding of Unicode for Internationalized Domain Names in Applications (IDNA) using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; @@ -142,7 +143,7 @@ public string GetUnicode(string ascii, int index, int count) } } - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is IdnMapping that && _allowUnassigned == that._allowUnassigned && _useStd3AsciiRules == that._useStd3AsciiRules; diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/RegionInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/RegionInfo.cs index 26375f2f69825..addd8a0a66785 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/RegionInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/RegionInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Globalization { @@ -184,7 +185,7 @@ public virtual string Name /// RegionInfos are considered equal if and only if they have the same name /// (ie: en-US) /// - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { return value is RegionInfo otherRegion && Name.Equals(otherRegion.Name); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs index 78e5117131e5d..db67dce64c5fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortKey.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Globalization { @@ -66,7 +67,7 @@ public static int Compare(SortKey sortkey1, SortKey sortkey2) return new ReadOnlySpan(key1Data).SequenceCompareTo(key2Data); } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { return value is SortKey other && new ReadOnlySpan(_keyData).SequenceEqual(other._keyData); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs index c146480e589ac..93ca171b29e31 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; namespace System.Globalization @@ -38,12 +39,12 @@ internal SortVersion(int nlsVersion, int effectiveId, Guid customVersion) m_SortId = customVersion; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is SortVersion otherVersion && Equals(otherVersion); } - public bool Equals(SortVersion? other) + public bool Equals([NotNullWhen(true)] SortVersion? other) { if (other == null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs index 85352ecb13ca9..fe9aee04dda0b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/StringInfo.cs @@ -27,7 +27,7 @@ public StringInfo(string value) this.String = value; } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { return value is StringInfo otherStringInfo && _str.Equals(otherStringInfo._str); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs index 109ebde2c24dd..38211f6158efc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; @@ -618,7 +619,7 @@ private void PopulateIsAsciiCasingSameAsInvariant() /// public bool IsRightToLeft => _cultureData.IsRightToLeft; - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is TextInfo otherTextInfo && CultureName.Equals(otherTextInfo.CultureName); diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.cs index 81a9910ee3370..19619cccc337e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.cs @@ -797,7 +797,7 @@ public override int GetHashCode() // Returns true if and only if the guid represented // by o is the same as this instance. - public override bool Equals(object? o) => o is Guid g && EqualsCore(this, g); + public override bool Equals([NotNullWhen(true)] object? o) => o is Guid g && EqualsCore(this, g); public bool Equals(Guid g) => EqualsCore(this, g); diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index 967c89960ef64..92ae792c854a7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -412,7 +412,7 @@ public int CompareTo(Half other) /// /// Returns a value that indicates whether this instance is equal to a specified . /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (obj is Half other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs index 235c8d96e2275..e5daba82dd6aa 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Path.cs @@ -295,7 +295,7 @@ public static bool IsPathFullyQualified(ReadOnlySpan path) /// Tests if a path's file name includes a file extension. A trailing period /// is not considered an extension. /// - public static bool HasExtension(string? path) + public static bool HasExtension([NotNullWhen(true)] string? path) { if (path != null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Index.cs b/src/libraries/System.Private.CoreLib/src/System/Index.cs index bb03c56c40ac5..7c8d00e0b2e36 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Index.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Index.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace System @@ -116,7 +117,7 @@ public int GetOffset(int length) /// Indicates whether the current Index object is equal to another object of the same type. /// An object to compare with this object - public override bool Equals(object? value) => value is Index && _value == ((Index)value)._value; + public override bool Equals([NotNullWhen(true)] object? value) => value is Index && _value == ((Index)value)._value; /// Indicates whether the current Index object is equal to another Index object. /// An object to compare with this object diff --git a/src/libraries/System.Private.CoreLib/src/System/Int16.cs b/src/libraries/System.Private.CoreLib/src/System/Int16.cs index c1375df6658d4..72278e5b5447b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int16.cs @@ -45,7 +45,7 @@ public int CompareTo(short value) return m_value - value; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is short)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Int32.cs b/src/libraries/System.Private.CoreLib/src/System/Int32.cs index de18cd3b84a73..213624a8fe515 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int32.cs @@ -56,7 +56,7 @@ public int CompareTo(int value) return 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is int)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Int64.cs b/src/libraries/System.Private.CoreLib/src/System/Int64.cs index d04e4efc4e172..0a8796e58f1e1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Int64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Int64.cs @@ -53,7 +53,7 @@ public int CompareTo(long value) return 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is long)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs index 455c941d94668..01229fff69b3d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IntPtr.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -72,7 +73,7 @@ unsafe void ISerializable.GetObjectData(SerializationInfo info, StreamingContext info.AddValue("value", ToInt64()); } - public override unsafe bool Equals(object? obj) => + public override unsafe bool Equals([NotNullWhen(true)] object? obj) => obj is IntPtr other && _value == other._value; @@ -216,13 +217,13 @@ public unsafe bool TryFormat(Span destination, out int charsWritten, ReadO public static IntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (IntPtr)nint_t.Parse(s, style, provider); public static IntPtr Parse(ReadOnlySpan s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null) => (IntPtr)nint_t.Parse(s, style, provider); - public static bool TryParse(string? s, out IntPtr result) + public static bool TryParse([NotNullWhen(true)] string? s, out IntPtr result) { Unsafe.SkipInit(out result); return nint_t.TryParse(s, out Unsafe.As(ref result)); } - public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out IntPtr result) + public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out IntPtr result) { Unsafe.SkipInit(out result); return nint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); diff --git a/src/libraries/System.Private.CoreLib/src/System/Memory.cs b/src/libraries/System.Private.CoreLib/src/System/Memory.cs index 531ec481e0446..f170027580762 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Memory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Memory.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; @@ -445,7 +446,7 @@ public unsafe MemoryHandle Pin() /// Returns true if the object is Memory or ReadOnlyMemory and if both objects point to the same array and have the same length. /// [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is ReadOnlyMemory) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.cs index e792c8b72620a..1735aabc36ca7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix3x2.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; @@ -584,7 +585,7 @@ public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2) /// The Object to compare against. /// True if the Object is equal to this matrix; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Matrix3x2 other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs index 8a350208d2aa1..8ede45904fbe9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Matrix4x4.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using Internal.Runtime.CompilerServices; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.Intrinsics; @@ -2115,7 +2116,7 @@ public static unsafe Matrix4x4 Transpose(Matrix4x4 matrix) /// The Object to compare against. /// True if the Object is equal to this matrix; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Matrix4x4 other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs index b2e8c41773654..984be6d7b3bc1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Plane.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; @@ -279,7 +280,7 @@ public static Plane Transform(Plane plane, Quaternion rotation) /// The Object to compare against. /// True if the Object is equal to this Plane; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Plane other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs index e1096b7b142e0..042ef0dac61d9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; @@ -581,7 +582,7 @@ public static Quaternion Subtract(Quaternion value1, Quaternion value2) /// Returns a boolean indicating whether the given Object is equal to this Quaternion instance. /// The Object to compare against. /// True if the Object is equal to this Quaternion; False otherwise. - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Quaternion other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs index 02a245bae0357..e1e5bce939120 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector2.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; using System.Text; @@ -503,7 +504,7 @@ public readonly void CopyTo(float[] array, int index) /// The Object to compare against. /// True if the Object is equal to this Vector2; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector2 other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs index 1c9a1d6124782..8d76f77343c66 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector3.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; using System.Text; @@ -530,7 +531,7 @@ public readonly void CopyTo(float[] array, int index) /// The Object to compare against. /// True if the Object is equal to this Vector3; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector3 other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs index 8958bcb5543a3..595a2bc1da16e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector4.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; using System.Text; @@ -619,7 +620,7 @@ public readonly bool Equals(Vector4 other) /// The Object to compare against. /// True if the Object is equal to this Vector4; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) + public override readonly bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector4 other) && Equals(other); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs index 4ddc73ca66a37..6d8c7f3276541 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Vector_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -258,7 +259,7 @@ public readonly unsafe T this[int index] /// The Object to compare against. /// True if the Object is equal to this vector; False otherwise. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override readonly bool Equals(object? obj) => (obj is Vector other) && Equals(other); + public override readonly bool Equals([NotNullWhen(true)] object? obj) => (obj is Vector other) && Equals(other); /// Returns a boolean indicating whether the given vector is equal to this vector instance. /// The vector to compare this instance to. diff --git a/src/libraries/System.Private.CoreLib/src/System/Range.cs b/src/libraries/System.Private.CoreLib/src/System/Range.cs index 0d6996da35c91..50dedb6efef27 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Range.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Range.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; #if NETSTANDARD2_0 || NETFRAMEWORK @@ -38,7 +39,7 @@ public Range(Index start, Index end) /// Indicates whether the current Range object is equal to another object of the same type. /// An object to compare with this object - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is Range r && r.Start.Equals(Start) && r.End.Equals(End); diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs index 105273a664921..124377cbea14a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; @@ -357,7 +358,7 @@ public unsafe MemoryHandle Pin() /// Determines whether the specified object is equal to the current object. [EditorBrowsable(EditorBrowsableState.Never)] - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is ReadOnlyMemory readOnlyMemory) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs index 8255d67195726..5c4c319d883ac 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ArrayWithOffset.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; namespace System.Runtime.InteropServices @@ -49,7 +50,7 @@ public ArrayWithOffset(object? array, int offset) public override int GetHashCode() => m_count + m_offset; - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CLong.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CLong.cs index 3d4e868c6b766..491f4ddbab53f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CLong.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CLong.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; #pragma warning disable SA1121 // We use our own aliases since they differ per platform @@ -54,7 +55,7 @@ public CLong(nint value) /// /// An object to compare with this instance. /// true if is an instance of and equals the value of this instance; otherwise, false. - public override bool Equals(object? o) => o is CLong other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? o) => o is CLong other && Equals(other); /// /// Returns a value indicating whether this instance is equal to a specified value. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CULong.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CULong.cs index 8ad64727e92bb..74bc9b35ad62a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CULong.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/CULong.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; #pragma warning disable SA1121 // We use our own aliases since they differ per platform @@ -54,7 +55,7 @@ public CULong(nuint value) /// /// An object to compare with this instance. /// true if is an instance of and equals the value of this instance; otherwise, false. - public override bool Equals(object? o) => o is CULong other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? o) => o is CULong other && Equals(other); /// /// Returns a value indicating whether this instance is equal to a specified value. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs index 02655498e2a83..b348c0b48161b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/GCHandle.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading; using Internal.Runtime.CompilerServices; @@ -162,7 +163,7 @@ public static GCHandle FromIntPtr(IntPtr value) public override int GetHashCode() => _handle.GetHashCode(); - public override bool Equals(object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle; + public override bool Equals([NotNullWhen(true)] object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle; public static bool operator ==(GCHandle a, GCHandle b) => a._handle == b._handle; diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs index 468d3e55ed5df..e3cb842f2a529 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; #pragma warning disable SA1121 // We use our own aliases since they differ per platform @@ -52,7 +53,7 @@ public NFloat(double value) /// /// An object to compare with this instance. /// true if is an instance of and equals the value of this instance; otherwise, false. - public override bool Equals(object? o) => o is NFloat other && Equals(other); + public override bool Equals([NotNullWhen(true)] object? o) => o is NFloat other && Equals(other); /// /// Returns a value indicating whether this instance is equal to a specified value. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs index ec1dafa002bef..8e09a52a035c3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -154,7 +155,7 @@ static bool SoftwareFallback(in Vector128 vector, Vector128 other) /// The object to compare with the current instance. /// true if is a and is equal to the current instance; otherwise, false. /// The type of the current instance () is not supported. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector128) && Equals((Vector128)(obj)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs index 8d03b115e3b5f..aaa57d1ed0060 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -157,7 +158,7 @@ static bool SoftwareFallback(in Vector256 vector, Vector256 other) /// The object to compare with the current instance. /// true if is a and is equal to the current instance; otherwise, false. /// The type of the current instance () is not supported. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector256) && Equals((Vector256)(obj)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs index 5e754fd285fa5..9f42fa6fdae01 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -112,7 +113,7 @@ public bool Equals(Vector64 other) /// The object to compare with the current instance. /// true if is a and is equal to the current instance; otherwise, false. /// The type of the current instance () is not supported. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (obj is Vector64) && Equals((Vector64)(obj)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/StreamingContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/StreamingContext.cs index 9083af164f473..3501457fa82d1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/StreamingContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/StreamingContext.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 System.Runtime.Serialization { public readonly struct StreamingContext @@ -18,7 +20,7 @@ public StreamingContext(StreamingContextStates state, object? additional) _additionalContext = additional; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is StreamingContext)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs index f3c1fc4064c8a..16f880e8591c9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Runtime.Versioning { @@ -74,12 +75,12 @@ public string FullName } } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as FrameworkName); } - public bool Equals(FrameworkName? other) + public bool Equals([NotNullWhen(true)] FrameworkName? other) { if (other is null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/SByte.cs b/src/libraries/System.Private.CoreLib/src/System/SByte.cs index 9e52b8cfee06f..24f3d5a640908 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SByte.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SByte.cs @@ -49,7 +49,7 @@ public int CompareTo(sbyte value) } // Determines whether two Byte objects are equal. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is sbyte)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs index 1a10767161ae4..fc331cc57fbf5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Security/SecurityElement.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text; namespace System.Security @@ -220,7 +221,7 @@ public void AddChild(SecurityElement child) _children.Add(child); } - public bool Equal(SecurityElement? other) + public bool Equal([NotNullWhen(true)] SecurityElement? other) { if (other == null) return false; @@ -297,7 +298,7 @@ public SecurityElement Copy() return element; } - public static bool IsValidTag(string? tag) + public static bool IsValidTag([NotNullWhen(true)] string? tag) { if (tag == null) return false; @@ -305,7 +306,7 @@ public static bool IsValidTag(string? tag) return tag.IndexOfAny(s_tagIllegalCharacters) == -1; } - public static bool IsValidText(string? text) + public static bool IsValidText([NotNullWhen(true)] string? text) { if (text == null) return false; @@ -313,12 +314,12 @@ public static bool IsValidText(string? text) return text.IndexOfAny(s_textIllegalCharacters) == -1; } - public static bool IsValidAttributeName(string? name) + public static bool IsValidAttributeName([NotNullWhen(true)] string? name) { return IsValidTag(name); } - public static bool IsValidAttributeValue(string? value) + public static bool IsValidAttributeValue([NotNullWhen(true)] string? value) { if (value == null) return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 163255f99ad25..2d9993203f96c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -208,7 +208,7 @@ public int CompareTo(float value) [NonVersionable] public static bool operator >=(float left, float right) => left >= right; - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is float)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs index bab6ff424b5b1..c3e9d2fa55c3a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Numerics; using System.Runtime.CompilerServices; @@ -604,7 +605,7 @@ public bool EndsWith(char value) } // Determines whether two strings match. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (object.ReferenceEquals(this, obj)) return true; @@ -619,7 +620,7 @@ public override bool Equals(object? obj) } // Determines whether two strings match. - public bool Equals(string? value) + public bool Equals([NotNullWhen(true)] string? value) { if (object.ReferenceEquals(this, value)) return true; @@ -637,7 +638,7 @@ public bool Equals(string? value) return EqualsHelper(this, value); } - public bool Equals(string? value, StringComparison comparisonType) + public bool Equals([NotNullWhen(true)] string? value, StringComparison comparisonType) { if (object.ReferenceEquals(this, value)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/StringComparer.cs b/src/libraries/System.Private.CoreLib/src/System/StringComparer.cs index c0f685b0a0ef9..15a1055607ac8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/StringComparer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/StringComparer.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; @@ -182,7 +183,7 @@ public override int GetHashCode(string obj) } // Equals method for the comparer itself. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is CultureAwareComparer comparer && @@ -265,7 +266,7 @@ public override int GetHashCode(string obj) } // Equals method for the comparer itself. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is OrdinalComparer comparer)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderExceptionFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderExceptionFallback.cs index cb46c711abbbd..94b9090114694 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderExceptionFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderExceptionFallback.cs @@ -17,7 +17,7 @@ public override DecoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => 0; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is DecoderExceptionFallback; public override int GetHashCode() => 879; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderReplacementFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderReplacementFallback.cs index 6bdc618b49576..2e4ebb3407309 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/DecoderReplacementFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/DecoderReplacementFallback.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Text { @@ -69,7 +70,7 @@ public override DecoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => _strDefault.Length; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is DecoderReplacementFallback that && _strDefault == that._strDefault; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderExceptionFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderExceptionFallback.cs index b57259cf67953..b314e6a19a4de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderExceptionFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderExceptionFallback.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.Serialization; namespace System.Text @@ -20,7 +21,7 @@ public override EncoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => 0; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is EncoderExceptionFallback; public override int GetHashCode() => 654; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderReplacementFallback.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderReplacementFallback.cs index a67e210b5b2b1..80298ca565c52 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncoderReplacementFallback.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncoderReplacementFallback.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Text { @@ -70,7 +71,7 @@ public override EncoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => _strDefault.Length; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is EncoderReplacementFallback that && _strDefault == that._strDefault; diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs index fb6ad0f4d0b28..1c7066e32f9b5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Encoding.cs @@ -1082,7 +1082,7 @@ public virtual string GetString(byte[] bytes, int index, int count) => private static Encoding BigEndianUTF32 => UTF32Encoding.s_bigEndianDefault; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is Encoding that && (_codePage == that._codePage) && (EncoderFallback.Equals(that.EncoderFallback)) && diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingInfo.cs index a2475ebc75642..55a0bd3de6af9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/EncodingInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/EncodingInfo.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 System.Text { public sealed class EncodingInfo @@ -59,7 +61,7 @@ internal EncodingInfo(int codePage, string name, string displayName) /// /// The other object to compare with this object /// True if the value object is EncodingInfo object and has a codepage equals to this EncodingInfo object codepage. Otherwise, it returns False - public override bool Equals(object? value) => value is EncodingInfo that && CodePage == that.CodePage; + public override bool Equals([NotNullWhen(true)] object? value) => value is EncodingInfo that && CodePage == that.CodePage; /// /// Get a hashcode representing the current EncodingInfo object. diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs index f2e1aa0c14acb..d0ea9ae9322a5 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/Rune.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Text.Unicode; @@ -758,7 +759,7 @@ public int EncodeToUtf8(Span destination) return bytesWritten; } - 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.Private.CoreLib/src/System/Text/StringBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs index bb4d3587b7ab8..7111d94bca5b9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/StringBuilder.cs @@ -1,11 +1,12 @@ // 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.Serialization; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -using System.Diagnostics; -using System.Collections.Generic; +using System.Runtime.Serialization; using Internal.Runtime.CompilerServices; namespace System.Text @@ -1808,7 +1809,7 @@ internal StringBuilder AppendFormatHelper(IFormatProvider? provider, string form /// Determines if the contents of this builder are equal to the contents of another builder. /// /// The other builder. - public bool Equals(StringBuilder? sb) + public bool Equals([NotNullWhen(true)] StringBuilder? sb) { if (sb == null) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs index 78b3bcf408c13..28b0161b18fe8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF32Encoding.cs @@ -6,6 +6,7 @@ // using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace System.Text @@ -1145,7 +1146,7 @@ public override byte[] GetPreamble() _bigEndian ? (ReadOnlySpan)new byte[4] { 0x00, 0x00, 0xFE, 0xFF } : // uses C# compiler's optimization for static byte[] data (ReadOnlySpan)new byte[4] { 0xFF, 0xFE, 0x00, 0x00 }; - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is UTF32Encoding that) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs index 70ab82f9e58ac..6ed4be774f714 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF7Encoding.cs @@ -102,7 +102,7 @@ internal sealed override void SetDefaultFallbacks() this.decoderFallback = new DecoderUTF7Fallback(); } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is UTF7Encoding that) { @@ -851,7 +851,7 @@ public override DecoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => 1; // returns 1 char per bad byte - public override bool Equals(object? value) => value is DecoderUTF7Fallback; + public override bool Equals([NotNullWhen(true)] object? value) => value is DecoderUTF7Fallback; public override int GetHashCode() => 984; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs index 2c7aed9b19279..7a20562189acc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UTF8Encoding.cs @@ -11,6 +11,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text.Unicode; @@ -836,7 +837,7 @@ public override byte[] GetPreamble() _emitUTF8Identifier ? PreambleSpan : default; - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is UTF8Encoding that) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs index 4d87f45015d9b..7e859d19e7afd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Text/UnicodeEncoding.cs @@ -10,6 +10,7 @@ #define FASTLOOP using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using Internal.Runtime.CompilerServices; @@ -1829,7 +1830,7 @@ public override int GetMaxCharCount(int byteCount) return (int)charCount; } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is UnicodeEncoding that) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationToken.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationToken.cs index 196956c57331a..c4ad9c658cc97 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationToken.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationToken.cs @@ -314,7 +314,7 @@ private CancellationTokenRegistration Register(Delegate callback, object? state, /// from public CancellationToken constructors and their values are equal. /// An associated CancellationTokenSource has been disposed. - public override bool Equals(object? other) => other is CancellationToken && Equals((CancellationToken)other); + public override bool Equals([NotNullWhen(true)] object? other) => other is CancellationToken && Equals((CancellationToken)other); /// /// Serves as a hash function for a CancellationToken. diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenRegistration.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenRegistration.cs index 5b892c91cf2ac..59b210c85d82d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenRegistration.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenRegistration.cs @@ -1,6 +1,7 @@ // 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; using System.Threading.Tasks; namespace System.Threading @@ -147,7 +148,7 @@ private ValueTask WaitForCallbackIfNecessaryAsync() /// they both refer to the output of a single call to the same Register method of a /// CancellationToken. /// - public override bool Equals(object? obj) => obj is CancellationTokenRegistration && Equals((CancellationTokenRegistration)obj); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is CancellationTokenRegistration && Equals((CancellationTokenRegistration)obj); /// /// Determines whether the current CancellationToken instance is equal to the diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs index 91586eff5f42d..f08b510ed3a76 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs @@ -605,7 +605,7 @@ public void Dispose() Undo(); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is AsyncFlowControl asyncControl && Equals(asyncControl); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs index 8fcbaca5da83f..6b6b86eb28b71 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/LowLevelLifoSemaphore.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace System.Threading @@ -352,7 +353,7 @@ public Counts InterlockedCompareExchange(Counts newCounts, Counts oldCounts) => public static bool operator ==(Counts lhs, Counts rhs) => lhs._data == rhs._data; public static bool operator !=(Counts lhs, Counts rhs) => lhs._data != rhs._data; - public override bool Equals(object? obj) => obj is Counts counts && _data == counts._data; + public override bool Equals([NotNullWhen(true)] object? obj) => obj is Counts counts && _data == counts._data; public override int GetHashCode() => (int)_data + (int)(_data >> 32); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs index 1587a3011a781..80ef3a5d4ac4c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.ThreadCounts.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Threading { @@ -88,7 +89,7 @@ public ThreadCounts InterlockedCompareExchange(ThreadCounts newCounts, ThreadCou public static bool operator ==(ThreadCounts lhs, ThreadCounts rhs) => lhs._data == rhs._data; public static bool operator !=(ThreadCounts lhs, ThreadCounts rhs) => lhs._data != rhs._data; - public override bool Equals(object? obj) => obj is ThreadCounts other && _data == other._data; + public override bool Equals([NotNullWhen(true)] object? obj) => obj is ThreadCounts other && _data == other._data; public override int GetHashCode() => (int)_data + (int)(_data >> 32); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs index 49e017435bcf7..1bdcf4fe131cf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerTracking.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Threading { @@ -118,7 +119,7 @@ public CountsOfThreadsProcessingUserCallbacks InterlockedCompareExchange( CountsOfThreadsProcessingUserCallbacks lhs, CountsOfThreadsProcessingUserCallbacks rhs) => lhs._data != rhs._data; - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is CountsOfThreadsProcessingUserCallbacks other && _data == other._data; public override int GetHashCode() => (int)_data; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs index 0139d9c20766e..be10b19c2a5bf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs @@ -148,7 +148,7 @@ public static ValueTask FromException(Exception exception) => public override int GetHashCode() => _obj?.GetHashCode() ?? 0; /// Returns a value indicating whether this value is equal to a specified . - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is ValueTask && Equals((ValueTask)obj); @@ -524,7 +524,7 @@ public override int GetHashCode() => 0; /// Returns a value indicating whether this value is equal to a specified . - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is ValueTask && Equals((ValueTask)obj); diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs index d7551477aa899..d0d03c0dfe5de 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeSpan.cs @@ -166,7 +166,7 @@ public TimeSpan Duration() return new TimeSpan(_ticks >= 0 ? _ticks : -_ticks); } - public override bool Equals(object? value) + public override bool Equals([NotNullWhen(true)] object? value) { if (value is TimeSpan) { diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.AdjustmentRule.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.AdjustmentRule.cs index 9e8c69203bd1a..caac7f0a4b3cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.AdjustmentRule.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.AdjustmentRule.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.Serialization; namespace System @@ -43,7 +44,7 @@ public sealed class AdjustmentRule : IEquatable, ISerializable, (DaylightTransitionStart != default && DaylightTransitionStart.TimeOfDay != DateTime.MinValue) || (DaylightTransitionEnd != default && DaylightTransitionEnd.TimeOfDay != DateTime.MinValue.AddMilliseconds(1)); - public bool Equals(AdjustmentRule? other) => + public bool Equals([NotNullWhen(true)] AdjustmentRule? other) => other != null && _dateStart == other._dateStart && _dateEnd == other._dateEnd && diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.TransitionTime.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.TransitionTime.cs index 942ae4f193a80..199b1dad8971c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.TransitionTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.TransitionTime.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.Serialization; namespace System @@ -29,7 +30,7 @@ public sealed partial class TimeZoneInfo public bool IsFixedDateRule => _isFixedDateRule; - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is TransitionTime && Equals((TransitionTime)obj); public static bool operator ==(TransitionTime t1, TransitionTime t2) => t1.Equals(t2); diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs index dacf92875a71d..3c8ddb932f348 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; using System.Threading; @@ -743,12 +744,12 @@ public static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo sourceTi /// Returns value equality. Equals does not compare any localizable /// String objects (DisplayName, StandardName, DaylightName). /// - public bool Equals(TimeZoneInfo? other) => + public bool Equals([NotNullWhen(true)] TimeZoneInfo? other) => other != null && string.Equals(_id, other._id, StringComparison.OrdinalIgnoreCase) && HasSameRules(other); - public override bool Equals(object? obj) => Equals(obj as TimeZoneInfo); + public override bool Equals([NotNullWhen(true)] object? obj) => Equals(obj as TimeZoneInfo); public static TimeZoneInfo FromSerializedString(string source) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Tuple.cs b/src/libraries/System.Private.CoreLib/src/System/Tuple.cs index d6e87002d5d56..3b8544db45873 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Tuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Tuple.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text; @@ -112,17 +113,17 @@ public Tuple(T1 item1) m_Item1 = item1; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -232,17 +233,17 @@ public Tuple(T1 item1, T2 item2) m_Item2 = item2; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -357,17 +358,17 @@ public Tuple(T1 item1, T2 item2, T3 item3) m_Item3 = item3; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -492,17 +493,17 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4) m_Item4 = item4; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -637,17 +638,17 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) m_Item5 = item5; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -792,17 +793,17 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) m_Item6 = item6; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -957,17 +958,17 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item m_Item7 = item7; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; @@ -1137,17 +1138,17 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item m_Rest = rest; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj, EqualityComparer.Default); } - bool IStructuralEquatable.Equals(object? other, IEqualityComparer comparer) + bool IStructuralEquatable.Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { return Equals(other, comparer); } - private bool Equals(object? other, IEqualityComparer comparer) + private bool Equals([NotNullWhen(true)] object? other, IEqualityComparer comparer) { if (other == null) return false; diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs index 0bd4dec69c0ae..b16a3b6e2543f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt16.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt16.cs @@ -44,7 +44,7 @@ public int CompareTo(ushort value) return (int)m_value - (int)value; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is ushort)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs index d347ed1385cc3..c5949d52ea54f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt32.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt32.cs @@ -54,7 +54,7 @@ public int CompareTo(uint value) return 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is uint)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs index 638821178f1dc..5b9ad1de4f84b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UInt64.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UInt64.cs @@ -54,7 +54,7 @@ public int CompareTo(ulong value) return 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is ulong)) { diff --git a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs index 26a093e9aefe6..c03e47fcf3fcc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs +++ b/src/libraries/System.Private.CoreLib/src/System/UIntPtr.cs @@ -1,6 +1,7 @@ // 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; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -68,7 +69,7 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex info.AddValue("value", ToUInt64()); } - public override unsafe bool Equals(object? obj) + public override unsafe bool Equals([NotNullWhen(true)] object? obj) { if (obj is UIntPtr) { @@ -208,13 +209,13 @@ public unsafe bool TryFormat(Span destination, out int charsWritten, ReadO public static UIntPtr Parse(string s, NumberStyles style, IFormatProvider? provider) => (UIntPtr)nuint_t.Parse(s, style, provider); public static UIntPtr Parse(ReadOnlySpan s, NumberStyles style = NumberStyles.Integer, IFormatProvider? provider = null) => (UIntPtr)nuint_t.Parse(s, style, provider); - public static bool TryParse(string? s, out UIntPtr result) + public static bool TryParse([NotNullWhen(true)] string? s, out UIntPtr result) { Unsafe.SkipInit(out result); return nuint_t.TryParse(s, out Unsafe.As(ref result)); } - public static bool TryParse(string? s, NumberStyles style, IFormatProvider? provider, out UIntPtr result) + public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, out UIntPtr result) { Unsafe.SkipInit(out result); return nuint_t.TryParse(s, style, provider, out Unsafe.As(ref result)); diff --git a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs index 73134ea840a85..5415a61d79076 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ValueTuple.cs @@ -6,6 +6,7 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -38,7 +39,7 @@ public struct ValueTuple /// /// The object to compare with this instance. /// if is a . - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple; } @@ -289,7 +290,7 @@ public ValueTuple(T1 item1) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -461,7 +462,7 @@ public ValueTuple(T1 item1, T2 item2) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -667,7 +668,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -872,7 +873,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -1095,7 +1096,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -1335,7 +1336,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -1593,7 +1594,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } @@ -1875,7 +1876,7 @@ public ValueTuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 /// Its components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. /// /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is ValueTuple tuple && Equals(tuple); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Version.cs b/src/libraries/System.Private.CoreLib/src/System/Version.cs index ec29f99c0cdc8..42df5d0c42739 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Version.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Version.cs @@ -148,12 +148,12 @@ public int CompareTo(Version? value) 0; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as Version); } - public bool Equals(Version? obj) + public bool Equals([NotNullWhen(true)] Version? obj) { return object.ReferenceEquals(obj, this) || (!(obj is null) && diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs index 53580ded68bbc..79742003b84f4 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Runtime.Serialization; using System.Diagnostics; - +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace System.Xml { @@ -177,7 +177,7 @@ public int CompareTo(PrefixHandle that) return GetString().CompareTo(that.GetString()); } - public bool Equals(PrefixHandle? prefix2) + public bool Equals([NotNullWhen(true)] PrefixHandle? prefix2) { if (prefix2 is null) return false; @@ -234,7 +234,7 @@ private bool Equals2(XmlDictionaryString prefix2) { return !prefix1.Equals(prefix2); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as PrefixHandle); } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs index fce097e9e1820..07d9bbb1ddac7 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs @@ -226,7 +226,7 @@ private bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2) return GetString() == _bufferReader.GetString(offset2, length2); } - public bool Equals(StringHandle? other) + public bool Equals([NotNullWhen(true)] StringHandle? other) { if (other is null) return false; @@ -275,7 +275,7 @@ public int CompareTo(StringHandle that) else return string.Compare(this.GetString(), that.GetString(), StringComparison.Ordinal); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as StringHandle); } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs index 662f2454c5146..de9f654f53d82 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.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 System.Xml { public class UniqueId @@ -332,7 +334,7 @@ public unsafe override string ToString() return !(id1 == id2); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return this == (obj as UniqueId); } diff --git a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs index 6d6d44a4181a9..45ea50ab75eb4 100644 --- a/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs +++ b/src/libraries/System.Private.Runtime.InteropServices.JavaScript/src/System/Runtime/InteropServices/JavaScript/JSObject.cs @@ -1,6 +1,7 @@ // 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; using Console = System.Diagnostics.Debug; namespace System.Runtime.InteropServices.JavaScript @@ -164,7 +165,7 @@ internal void FreeHandle() FreeGCHandle(); } - public override bool Equals(object? obj) => obj is JSObject other && JSHandle == other.JSHandle; + public override bool Equals([NotNullWhen(true)] object? obj) => obj is JSObject other && JSHandle == other.JSHandle; public override int GetHashCode() => JSHandle; diff --git a/src/libraries/System.Private.Uri/src/System/Uri.cs b/src/libraries/System.Private.Uri/src/System/Uri.cs index cfa15a2d18e9f..b589ffa69a284 100644 --- a/src/libraries/System.Private.Uri/src/System/Uri.cs +++ b/src/libraries/System.Private.Uri/src/System/Uri.cs @@ -4,6 +4,7 @@ using Internal.Runtime.CompilerServices; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.Serialization; @@ -1468,7 +1469,7 @@ public static bool IsHexEncoding(string pattern, int index) // Syntax is: // scheme = alpha *(alpha | digit | '+' | '-' | '.') // - public static bool CheckSchemeName(string? schemeName) + public static bool CheckSchemeName([NotNullWhen(true)] string? schemeName) { if (string.IsNullOrEmpty(schemeName) || !UriHelper.IsAsciiLetter(schemeName[0])) { @@ -1619,7 +1620,7 @@ public override string ToString() // Throws: // Nothing // - public override bool Equals(object? comparand) + public override bool Equals([NotNullWhen(true)] object? comparand) { if (comparand is null) { diff --git a/src/libraries/System.Private.Uri/src/System/UriBuilder.cs b/src/libraries/System.Private.Uri/src/System/UriBuilder.cs index 049d5d44f84ee..e75fb04af116f 100644 --- a/src/libraries/System.Private.Uri/src/System/UriBuilder.cs +++ b/src/libraries/System.Private.Uri/src/System/UriBuilder.cs @@ -351,7 +351,7 @@ public string UserName // methods - public override bool Equals(object? rparam) + public override bool Equals([NotNullWhen(true)] object? rparam) { if (rparam == null) { diff --git a/src/libraries/System.Private.Uri/src/System/UriExt.cs b/src/libraries/System.Private.Uri/src/System/UriExt.cs index ca43d833a79de..72c266d0487c1 100644 --- a/src/libraries/System.Private.Uri/src/System/UriExt.cs +++ b/src/libraries/System.Private.Uri/src/System/UriExt.cs @@ -246,7 +246,7 @@ private static bool CheckForUnicodeOrEscapedUnreserved(string data) // Returns true if the string represents a valid argument to the Uri ctor // If uriKind != AbsoluteUri then certain parsing errors are ignored but Uri usage is limited // - public static bool TryCreate(string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result) + public static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result) { if (uriString is null) { diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XName.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XName.cs index 66ab4828ffa09..15d3987286556 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XName.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XName.cs @@ -118,7 +118,7 @@ public static XName Get(string localName, string namespaceName) /// /// For two objects to be equal, they must have the same expanded name. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (object)this == obj; } diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs index c3fa5a3d85ac1..2e38ae7a947be 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XNamespace.cs @@ -153,7 +153,7 @@ public static XNamespace Get(string namespaceName) /// For two objects to be equal they must have the same /// namespace name. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return (object)this == obj; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs index eab6cb679f3da..d31976925b065 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/XmlBinaryReader.cs @@ -5,6 +5,7 @@ using System.Buffers.Binary; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Runtime.InteropServices; @@ -105,7 +106,7 @@ public int GetNSHashCode() } - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { if (other is QName that) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentNavigator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentNavigator.cs index 094016bf610d3..d0973571ab3a1 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentNavigator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathDocumentNavigator.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Xml; using System.Xml.XPath; @@ -813,7 +814,7 @@ public override XmlNodeOrder ComparePosition(XPathNavigator? other) /// /// Return true if the "other" navigator's current node is a descendant of this navigator's current node. /// - public override bool IsDescendant(XPathNavigator? other) + public override bool IsDescendant([NotNullWhen(true)] XPathNavigator? other) { XPathDocumentNavigator? that = other as XPathDocumentNavigator; if (that != null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs index 0c23b91e6fcd5..9afbc4f400bd7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Cache/XPathNodeInfoAtom.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Xml.XPath; @@ -280,7 +281,7 @@ public override int GetHashCode() /// /// Return true if this InfoAtom has the same values as another InfoAtom. /// - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { return Equals(other as XPathNodeInfoAtom); } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXPathNavigator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXPathNavigator.cs index 125e8287ebfff..84d4fa56c2880 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXPathNavigator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/DocumentXPathNavigator.cs @@ -1226,7 +1226,7 @@ public override bool IsSamePosition(XPathNavigator other) return false; } - public override bool IsDescendant(XPathNavigator? other) + public override bool IsDescendant([NotNullWhen(true)] XPathNavigator? other) { if (other is DocumentXPathNavigator that) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/BitSet.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/BitSet.cs index d389ff72a5bc5..de7d324e3df3c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/BitSet.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/BitSet.cs @@ -1,11 +1,12 @@ // 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; +using System.Diagnostics.CodeAnalysis; +using System.Text; + namespace System.Xml.Schema { - using System.Text; - using System.Diagnostics; - internal sealed class BitSet { private const int bitSlotShift = 5; @@ -148,7 +149,7 @@ public override int GetHashCode() } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { // assume the same type if (obj != null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Chameleonkey.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Chameleonkey.cs index 207a67d9f4280..a147f5a964777 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Chameleonkey.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Chameleonkey.cs @@ -1,13 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections; +using System.ComponentModel; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Xml.Serialization; + namespace System.Xml.Schema { - using System.Collections; - using System.ComponentModel; - using System.Diagnostics; - using System.Xml.Serialization; - // Case insensitive file name key for use in a hashtable. internal class ChameleonKey @@ -49,7 +50,7 @@ public override int GetHashCode() return _hashCode; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (Ref.ReferenceEquals(this, obj)) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ConstraintStruct.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ConstraintStruct.cs index 0ddc7dba2bfba..15148e530cddc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ConstraintStruct.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ConstraintStruct.cs @@ -1,16 +1,17 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Collections; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Text; +using System.Xml.XPath; +using MS.Internal.Xml.XPath; + namespace System.Xml.Schema { - using System; - using System.Text; - using System.Collections; - using System.Globalization; - using System.Diagnostics; - using System.Xml.XPath; - using MS.Internal.Xml.XPath; - internal sealed class ConstraintStruct { // for each constraint @@ -485,7 +486,7 @@ public override int GetHashCode() } // considering about derived type - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { // each key sequence member can have different type if (other is KeySequence keySequence) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaType.cs index 48a6c3129357d..1b0e7934b1a0a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaType.cs @@ -280,7 +280,7 @@ internal void SetContentType(XmlSchemaContentType value) _contentType = value; } - public static bool IsDerivedFrom(XmlSchemaType? derivedType, XmlSchemaType? baseType, XmlSchemaDerivationMethod except) + public static bool IsDerivedFrom([NotNullWhen(true)] XmlSchemaType? derivedType, [NotNullWhen(true)] XmlSchemaType? baseType, XmlSchemaDerivationMethod except) { if (derivedType == null || baseType == null) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs index 622d0fd3331d8..f6be0bfb5afbc 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Compilation.cs @@ -641,7 +641,7 @@ internal TempAssemblyCacheKey(string? ns, object type) _ns = ns; } - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { TempAssemblyCacheKey? key = o as TempAssemblyCacheKey; if (key == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/NameTable.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/NameTable.cs index 604e61c980e8a..3ddda81e40268 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/NameTable.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/NameTable.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 System.Xml.Serialization { using System.Xml; @@ -19,7 +21,7 @@ internal NameKey(string? name, string? ns) _ns = ns; } - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { if (!(other is NameKey)) return false; NameKey key = (NameKey)other; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs index d299f299f6cbd..eb99da1a1686d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Reflection.Emit; using System.Text.RegularExpressions; @@ -245,7 +246,7 @@ public static implicit operator string(SourceInfo source) return b is null; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null) return Source == null; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index 8c9b1d98859e8..67b49b7b39a8d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -1,24 +1,25 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Reflection; +using System.Runtime.Versioning; +using System.Security; +using System.Text; +using System.Threading; +using System.Xml; +using System.Xml.Schema; +using System.Xml.Serialization; +using System.Xml.Serialization.Configuration; + namespace System.Xml.Serialization { - using System.Reflection; - using System.Collections; - using System.IO; - using System.Xml.Schema; - using System; - using System.Text; - using System.Threading; - using System.Globalization; - using System.Security; - using System.Xml.Serialization.Configuration; - using System.Diagnostics; - using System.Collections.Generic; - using System.Runtime.Versioning; - using System.Xml; - using System.Xml.Serialization; - public struct XmlDeserializationEvents { private XmlNodeEventHandler? _onUnknownNode; @@ -951,7 +952,7 @@ public XmlSerializerMappingKey(XmlMapping mapping) this.Mapping = mapping; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { XmlSerializerMappingKey? other = obj as XmlSerializerMappingKey; if (other == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs index 3bfdd36d5005c..63ca7e274c53f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml { @@ -86,7 +87,7 @@ public override string ToString() /// /// [To be supplied.] /// - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { if ((object)this == other) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs index 626bd17bae913..8e3e1a4b841a7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Pair.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Xml.Xsl { @@ -20,7 +21,7 @@ public Int32Pair(int left, int right) public int Left { get { return _left; } } public int Right { get { return _right; } } - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { if (other is Int32Pair) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs index 12bda6fd43356..f39da3bacf554 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs @@ -92,7 +92,7 @@ public override int GetHashCode() /// Override Equals() so that the QilName can be used as a key in the hashtable. /// /// Does not compare their prefixes (if any). - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { QilName? name = other as QilName; if (name == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs index bf46143f278a8..1046765a2d3b2 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryCardinality.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; namespace System.Xml.Xsl @@ -119,7 +120,7 @@ public bool Equals(XmlQueryCardinality other) /// /// True if "other" is an XmlQueryCardinality, and this type is the exact same static type. /// - public override bool Equals(object? other) + public override bool Equals([NotNullWhen(true)] object? other) { if (other is XmlQueryCardinality) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs index 0883d4d5846aa..be4b0fbc9e854 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; using System.Xml.Schema; @@ -167,7 +168,7 @@ public bool NeverSubtypeOf(XmlQueryType baseType) /// /// Strongly-typed Equals that returns true if this type and "that" type are equivalent. /// - public bool Equals(XmlQueryType? that) + public bool Equals([NotNullWhen(true)] XmlQueryType? that) { if (that == null) return false; @@ -318,7 +319,7 @@ public bool IsNumeric /// /// True if "obj" is an XmlQueryType, and this type is the exact same static type. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { XmlQueryType? that = obj as XmlQueryType; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs index 744793ab723c7..e3e8331c6e127 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/CompilerScopeManager.cs @@ -98,7 +98,7 @@ public void CheckEmpty() } // returns true if ns decls was added to scope - public bool EnterScope(NsDecl? nsDecl) + public bool EnterScope([NotNullWhen(true)] NsDecl? nsDecl) { _lastScopes++; diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs index eb1abb41102b5..f5ed97de3b96b 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/ref/System.Runtime.InteropServices.RuntimeInformation.cs @@ -23,7 +23,7 @@ public enum Architecture public static System.Runtime.InteropServices.OSPlatform OSX { get { throw null; } } public static System.Runtime.InteropServices.OSPlatform Windows { get { throw null; } } public static System.Runtime.InteropServices.OSPlatform Create(string osPlatform) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.InteropServices.OSPlatform other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Runtime.InteropServices.OSPlatform left, System.Runtime.InteropServices.OSPlatform right) { throw null; } diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs index 91dcbad86e174..ff36163ba1c3c 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/OSPlatform.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 System.Runtime.InteropServices { public readonly struct OSPlatform : IEquatable @@ -42,7 +44,7 @@ internal bool Equals(string? other) return string.Equals(Name, other, StringComparison.OrdinalIgnoreCase); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is OSPlatform osPlatform && Equals(osPlatform); } diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index e8132bb910a2b..e2523829b9e60 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -103,7 +103,7 @@ public partial struct ArrayWithOffset private object _dummy; private int _dummyPrimitive; public ArrayWithOffset(object? array, int offset) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.InteropServices.ArrayWithOffset obj) { throw null; } public object? GetArray() { throw null; } public override int GetHashCode() { throw null; } @@ -162,7 +162,7 @@ public enum ClassInterfaceType public CLong(int value) { } public CLong(nint value) { } public nint Value { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public bool Equals(CLong other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } @@ -297,7 +297,7 @@ public ComUnregisterFunctionAttribute() { } public CULong(uint value) { } public CULong(nuint value) { } public nuint Value { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public bool Equals(CULong other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } @@ -762,7 +762,7 @@ public static void SetDllImportResolver(System.Reflection.Assembly assembly, Sys public NFloat(float value) { } public NFloat(double value) { } public double Value { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public bool Equals(NFloat other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } diff --git a/src/libraries/System.Runtime.Intrinsics/ref/System.Runtime.Intrinsics.cs b/src/libraries/System.Runtime.Intrinsics/ref/System.Runtime.Intrinsics.cs index 33fc1f798e551..6cf453fd8d0c8 100644 --- a/src/libraries/System.Runtime.Intrinsics/ref/System.Runtime.Intrinsics.cs +++ b/src/libraries/System.Runtime.Intrinsics/ref/System.Runtime.Intrinsics.cs @@ -117,7 +117,7 @@ public static partial class Vector128 public static System.Runtime.Intrinsics.Vector128 AllBitsSet { get { throw null; } } public static int Count { get { throw null; } } public static System.Runtime.Intrinsics.Vector128 Zero { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.Intrinsics.Vector128 other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } @@ -225,7 +225,7 @@ public static partial class Vector256 public static System.Runtime.Intrinsics.Vector256 AllBitsSet { get { throw null; } } public static int Count { get { throw null; } } public static System.Runtime.Intrinsics.Vector256 Zero { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.Intrinsics.Vector256 other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } @@ -307,7 +307,7 @@ public static partial class Vector64 public static System.Runtime.Intrinsics.Vector64 AllBitsSet { get { throw null; } } public static int Count { get { throw null; } } public static System.Runtime.Intrinsics.Vector64 Zero { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.Intrinsics.Vector64 other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } diff --git a/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs b/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs index e0e19a4c6ff64..fcb447ecf34f5 100644 --- a/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs +++ b/src/libraries/System.Runtime.Numerics/ref/System.Runtime.Numerics.cs @@ -42,7 +42,7 @@ namespace System.Numerics public static System.Numerics.BigInteger DivRem(System.Numerics.BigInteger dividend, System.Numerics.BigInteger divisor, out System.Numerics.BigInteger remainder) { throw null; } public bool Equals(long other) { throw null; } public bool Equals(System.Numerics.BigInteger other) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } [System.CLSCompliantAttribute(false)] public bool Equals(ulong other) { throw null; } public long GetBitLength() { throw null; } @@ -192,7 +192,7 @@ public partial struct Complex : System.IEquatable, Syst public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, double divisor) { throw null; } public static System.Numerics.Complex Divide(System.Numerics.Complex dividend, System.Numerics.Complex divisor) { throw null; } public bool Equals(System.Numerics.Complex value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Numerics.Complex Exp(System.Numerics.Complex value) { throw null; } public static System.Numerics.Complex FromPolarCoordinates(double magnitude, double phase) { throw null; } public override int GetHashCode() { throw null; } diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index 91a05bdb9c849..58ac3ee501202 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -995,7 +995,7 @@ public override int GetHashCode() return hash; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { AssertValid(); diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs index 7b4ab6443d64a..78b7c8124db91 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/Complex.cs @@ -368,7 +368,7 @@ public static Complex Reciprocal(Complex value) return left.m_real != right.m_real || left.m_imaginary != right.m_imaginary; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is Complex)) return false; return Equals((Complex)obj); diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs index 2f46ebc96742e..5d840937a0a18 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/MemberHolder.cs @@ -21,7 +21,7 @@ internal MemberHolder( public override int GetHashCode() => _memberType.GetHashCode(); - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is MemberHolder mh && ReferenceEquals(mh._memberType, _memberType) && diff --git a/src/libraries/System.Runtime.Serialization.Xml/ref/System.Runtime.Serialization.Xml.cs b/src/libraries/System.Runtime.Serialization.Xml/ref/System.Runtime.Serialization.Xml.cs index 00c98216132cc..4c16924a5e827 100644 --- a/src/libraries/System.Runtime.Serialization.Xml/ref/System.Runtime.Serialization.Xml.cs +++ b/src/libraries/System.Runtime.Serialization.Xml/ref/System.Runtime.Serialization.Xml.cs @@ -169,7 +169,7 @@ public UniqueId(System.Guid guid) { } public UniqueId(string value) { } public int CharArrayLength { get { throw null; } } public bool IsGuid { get { 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 ==(System.Xml.UniqueId? id1, System.Xml.UniqueId? id2) { throw null; } public static bool operator !=(System.Xml.UniqueId? id1, System.Xml.UniqueId? id2) { throw null; } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index 183a202d943ae..67894c177737d 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -238,7 +238,7 @@ public ApplicationId(byte[] publicKeyToken, string name, System.Version version, public byte[] PublicKeyToken { get { throw null; } } public System.Version Version { get { throw null; } } public System.ApplicationId Copy() { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -435,7 +435,7 @@ public void CopyTo(System.ArraySegment destination) { } public void CopyTo(T[] destination) { } public void CopyTo(T[] destination, int destinationIndex) { } public bool Equals(System.ArraySegment obj) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public System.ArraySegment.Enumerator GetEnumerator() { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.ArraySegment a, System.ArraySegment b) { throw null; } @@ -484,7 +484,7 @@ public abstract partial class Attribute { protected Attribute() { } public virtual object TypeId { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Attribute? GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType) { throw null; } public static System.Attribute? GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType, bool inherit) { throw null; } public static System.Attribute? GetCustomAttribute(System.Reflection.MemberInfo element, System.Type attributeType) { throw null; } @@ -646,7 +646,7 @@ public static partial class BitConverter public int CompareTo(System.Boolean value) { throw null; } public int CompareTo(object? obj) { throw null; } public System.Boolean Equals(System.Boolean obj) { throw null; } - public override System.Boolean Equals(object? obj) { throw null; } + public override System.Boolean Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } public static System.Boolean Parse(System.ReadOnlySpan value) { throw null; } @@ -691,7 +691,7 @@ public static void SetByte(System.Array array, int index, byte value) { } public int CompareTo(System.Byte value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.Byte obj) { 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 System.TypeCode GetTypeCode() { throw null; } public static System.Byte Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider? provider = null) { throw null; } @@ -743,7 +743,7 @@ public CannotUnloadAppDomainException(string? message, System.Exception? innerEx public static int ConvertToUtf32(System.Char highSurrogate, System.Char lowSurrogate) { throw null; } public static int ConvertToUtf32(string s, int index) { throw null; } public bool Equals(System.Char obj) { 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 double GetNumericValue(System.Char c) { throw null; } public static double GetNumericValue(string s, int index) { throw null; } @@ -871,13 +871,13 @@ public static partial class Convert public static bool ToBoolean(short value) { throw null; } public static bool ToBoolean(int value) { throw null; } public static bool ToBoolean(long value) { throw null; } - public static bool ToBoolean(object? value) { throw null; } - public static bool ToBoolean(object? value, System.IFormatProvider? provider) { throw null; } + public static bool ToBoolean([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } + public static bool ToBoolean([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value, System.IFormatProvider? provider) { throw null; } [System.CLSCompliantAttribute(false)] public static bool ToBoolean(sbyte value) { throw null; } public static bool ToBoolean(float value) { throw null; } - public static bool ToBoolean(string? value) { throw null; } - public static bool ToBoolean(string? value, System.IFormatProvider? provider) { throw null; } + public static bool ToBoolean([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value) { throw null; } + public static bool ToBoolean([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value, System.IFormatProvider? provider) { throw null; } [System.CLSCompliantAttribute(false)] public static bool ToBoolean(ushort value) { throw null; } [System.CLSCompliantAttribute(false)] @@ -1342,7 +1342,7 @@ public static partial class Convert public static int DaysInMonth(int year, int month) { throw null; } public bool Equals(System.DateTime value) { throw null; } public static bool Equals(System.DateTime t1, System.DateTime t2) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public static System.DateTime FromBinary(long dateData) { throw null; } public static System.DateTime FromFileTime(long fileTime) { throw null; } public static System.DateTime FromFileTimeUtc(long fileTime) { throw null; } @@ -1466,7 +1466,7 @@ public enum DateTimeKind public int CompareTo(System.DateTimeOffset other) { throw null; } public bool Equals(System.DateTimeOffset other) { throw null; } public static bool Equals(System.DateTimeOffset first, System.DateTimeOffset second) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool EqualsExact(System.DateTimeOffset other) { throw null; } public static System.DateTimeOffset FromFileTime(long fileTime) { throw null; } public static System.DateTimeOffset FromUnixTimeMilliseconds(long milliseconds) { throw null; } @@ -1582,7 +1582,7 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S public static System.Decimal Divide(System.Decimal d1, System.Decimal d2) { throw null; } public bool Equals(System.Decimal value) { throw null; } public static bool Equals(System.Decimal d1, System.Decimal d2) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public static System.Decimal Floor(System.Decimal d) { throw null; } public static System.Decimal FromOACurrency(long cy) { throw null; } public static int[] GetBits(System.Decimal d) { throw null; } @@ -1719,7 +1719,7 @@ protected Delegate([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAt public static System.Delegate? CreateDelegate(System.Type type, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type target, string method, bool ignoreCase, bool throwOnBindFailure) { throw null; } public object? DynamicInvoke(params object?[]? args) { throw null; } protected virtual object? DynamicInvokeImpl(object?[]? args) { 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 virtual System.Delegate[] GetInvocationList() { throw null; } protected virtual System.Reflection.MethodInfo GetMethodImpl() { throw null; } @@ -1749,7 +1749,7 @@ public DivideByZeroException(string? message, System.Exception? innerException) public int CompareTo(System.Double value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.Double obj) { 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 System.TypeCode GetTypeCode() { throw null; } public static bool IsFinite(System.Double d) { throw null; } @@ -1815,7 +1815,7 @@ public abstract partial class Enum : System.ValueType, System.IComparable, Syste { protected Enum() { } public int CompareTo(object? target) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static string Format(System.Type enumType, object value, string format) { throw null; } public override int GetHashCode() { throw null; } public static string? GetName(System.Type enumType, object value) { throw null; } @@ -1869,8 +1869,8 @@ protected Enum() { } public string ToString(string? format, System.IFormatProvider? provider) { throw null; } public static bool TryParse(System.Type enumType, string? value, bool ignoreCase, out object? result) { throw null; } public static bool TryParse(System.Type enumType, string? value, out object? result) { throw null; } - public static bool TryParse(string? value, bool ignoreCase, out TEnum result) where TEnum : struct { throw null; } - public static bool TryParse(string? value, out TEnum result) where TEnum : struct { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value, bool ignoreCase, out TEnum result) where TEnum : struct { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value, out TEnum result) where TEnum : struct { throw null; } } public static partial class Environment { @@ -2191,7 +2191,7 @@ public GopherStyleUriParser() { } public int CompareTo(System.Guid value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.Guid g) { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public static System.Guid NewGuid() { throw null; } public static bool operator ==(System.Guid a, System.Guid b) { throw null; } @@ -2223,7 +2223,7 @@ public GopherStyleUriParser() { } public int CompareTo(System.Half other) { throw null; } public int CompareTo(object? obj) { throw null; } public bool Equals(System.Half 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 IsFinite(System.Half value) { throw null; } public static bool IsInfinity(System.Half value) { throw null; } @@ -2356,7 +2356,7 @@ public partial interface IFormattable public static System.Index Start { get { throw null; } } public int Value { get { throw null; } } public bool Equals(System.Index other) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public static System.Index FromEnd(int value) { throw null; } public static System.Index FromStart(int value) { throw null; } public override int GetHashCode() { throw null; } @@ -2390,7 +2390,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public int CompareTo(System.Int16 value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.Int16 obj) { 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 System.TypeCode GetTypeCode() { throw null; } public static System.Int16 Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider? provider = null) { throw null; } @@ -2431,7 +2431,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public System.Int32 CompareTo(System.Int32 value) { throw null; } public System.Int32 CompareTo(object? value) { throw null; } public bool Equals(System.Int32 obj) { 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 System.Int32 GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } public static System.Int32 Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider? provider = null) { throw null; } @@ -2472,7 +2472,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public int CompareTo(System.Int64 value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.Int64 obj) { 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 System.TypeCode GetTypeCode() { throw null; } public static System.Int64 Parse(System.ReadOnlySpan s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.Integer, System.IFormatProvider? provider = null) { throw null; } @@ -2520,7 +2520,7 @@ public InsufficientMemoryException(string? message, System.Exception? innerExcep public int CompareTo(System.IntPtr value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.IntPtr 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 System.IntPtr operator +(System.IntPtr pointer, int offset) { throw null; } public static bool operator ==(System.IntPtr value1, System.IntPtr value2) { throw null; } @@ -2550,8 +2550,8 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public string ToString(System.IFormatProvider? provider) { throw null; } public string ToString(string? format) { throw null; } public string ToString(string? format, System.IFormatProvider? provider) { throw null; } - public static bool TryParse(string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.IntPtr result) { throw null; } - public static bool TryParse(string? s, out System.IntPtr result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.IntPtr result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.IntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.IntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.IntPtr result) { throw null; } } @@ -2867,7 +2867,7 @@ public MemberAccessException(string? message, System.Exception? inner) { } public void CopyTo(System.Memory destination) { } public bool Equals(System.Memory other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } public static implicit operator System.Memory (System.ArraySegment segment) { throw null; } @@ -2933,7 +2933,7 @@ public partial struct ModuleHandle public static readonly System.ModuleHandle EmptyHandle; public int MDStreamVersion { get { throw null; } } public bool Equals(System.ModuleHandle handle) { 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 System.RuntimeFieldHandle GetRuntimeFieldHandleFromMetadataToken(int fieldToken) { throw null; } public System.RuntimeMethodHandle GetRuntimeMethodHandleFromMetadataToken(int methodToken) { throw null; } @@ -2958,7 +2958,7 @@ public abstract partial class MulticastDelegate : System.Delegate protected MulticastDelegate(object target, string method) : base (default(object), default(string)) { } protected MulticastDelegate([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type target, string method) : base (default(object), default(string)) { } protected sealed override System.Delegate CombineImpl(System.Delegate? follow) { throw null; } - public sealed override bool Equals(object? obj) { throw null; } + public sealed override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public sealed override int GetHashCode() { throw null; } public sealed override System.Delegate[] GetInvocationList() { throw null; } protected override System.Reflection.MethodInfo GetMethodImpl() { throw null; } @@ -3192,7 +3192,7 @@ public virtual void NextBytes(System.Span buffer) { } public System.Index End { get { throw null; } } public System.Index Start { get { throw null; } } public static System.Range EndAt(System.Index end) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public bool Equals(System.Range other) { throw null; } public override int GetHashCode() { throw null; } public (int Offset, int Length) GetOffsetAndLength(int length) { throw null; } @@ -3218,7 +3218,7 @@ public RankException(string? message, System.Exception? innerException) { } public System.ReadOnlySpan Span { get { throw null; } } public void CopyTo(System.Memory destination) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.ReadOnlyMemory other) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public override int GetHashCode() { throw null; } @@ -3330,7 +3330,7 @@ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, S public const sbyte MinValue = (sbyte)-128; public int CompareTo(object? obj) { throw null; } public int CompareTo(System.SByte value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.SByte obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } @@ -3380,7 +3380,7 @@ public SerializableAttribute() { } public const float PositiveInfinity = 1.0f / 0.0f; public int CompareTo(object? value) { throw null; } public int CompareTo(System.Single value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Single obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } @@ -3543,8 +3543,8 @@ public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, in public bool EndsWith(System.String value, bool ignoreCase, System.Globalization.CultureInfo? culture) { throw null; } public bool EndsWith(System.String value, System.StringComparison comparisonType) { throw null; } public System.Text.StringRuneEnumerator EnumerateRunes() { throw null; } - public override bool Equals(object? obj) { throw null; } - public bool Equals(System.String? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.String? value) { throw null; } public static bool Equals(System.String? a, System.String? b) { throw null; } public static bool Equals(System.String? a, System.String? b, System.StringComparison comparisonType) { throw null; } public bool Equals(System.String? value, System.StringComparison comparisonType) { throw null; } @@ -3767,7 +3767,7 @@ public TimeoutException(string? message, System.Exception? innerException) { } public System.TimeSpan Divide(double divisor) { throw null; } public double Divide(System.TimeSpan ts) { throw null; } public System.TimeSpan Duration() { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public bool Equals(System.TimeSpan obj) { throw null; } public static bool Equals(System.TimeSpan t1, System.TimeSpan t2) { throw null; } public static System.TimeSpan FromDays(double value) { throw null; } @@ -3858,7 +3858,7 @@ public static void ClearCachedData() { } public static System.TimeZoneInfo CreateCustomTimeZone(string id, System.TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName) { throw null; } public static System.TimeZoneInfo CreateCustomTimeZone(string id, System.TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, System.TimeZoneInfo.AdjustmentRule[]? adjustmentRules) { throw null; } public static System.TimeZoneInfo CreateCustomTimeZone(string id, System.TimeSpan baseUtcOffset, string? displayName, string? standardDisplayName, string? daylightDisplayName, System.TimeZoneInfo.AdjustmentRule[]? adjustmentRules, bool disableDaylightSavingTime) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.TimeZoneInfo? other) { throw null; } public static System.TimeZoneInfo FindSystemTimeZoneById(string id) { throw null; } public static System.TimeZoneInfo FromSerializedString(string source) { throw null; } @@ -3888,7 +3888,7 @@ internal AdjustmentRule() { } public System.TimeZoneInfo.TransitionTime DaylightTransitionEnd { get { throw null; } } public System.TimeZoneInfo.TransitionTime DaylightTransitionStart { get { throw null; } } public static System.TimeZoneInfo.AdjustmentRule CreateAdjustmentRule(System.DateTime dateStart, System.DateTime dateEnd, System.TimeSpan daylightDelta, System.TimeZoneInfo.TransitionTime daylightTransitionStart, System.TimeZoneInfo.TransitionTime daylightTransitionEnd) { throw null; } - public bool Equals(System.TimeZoneInfo.AdjustmentRule? other) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.TimeZoneInfo.AdjustmentRule? other) { throw null; } public override int GetHashCode() { throw null; } void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } @@ -3904,7 +3904,7 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public int Week { get { throw null; } } public static System.TimeZoneInfo.TransitionTime CreateFixedDateRule(System.DateTime timeOfDay, int month, int day) { throw null; } public static System.TimeZoneInfo.TransitionTime CreateFloatingDateRule(System.DateTime timeOfDay, int month, int week, System.DayOfWeek dayOfWeek) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.TimeZoneInfo.TransitionTime other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.TimeZoneInfo.TransitionTime t1, System.TimeZoneInfo.TransitionTime t2) { throw null; } @@ -4024,7 +4024,7 @@ public Tuple(T1 item1) { } public T1 Item1 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4039,7 +4039,7 @@ public Tuple(T1 item1, T2 item2) { } public T2 Item2 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4055,7 +4055,7 @@ public Tuple(T1 item1, T2 item2, T3 item3) { } public T3 Item3 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4072,7 +4072,7 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4) { } public T4 Item4 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4090,7 +4090,7 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5) { } public T5 Item5 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4109,7 +4109,7 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { } public T6 Item6 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4129,7 +4129,7 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item public T7 Item7 { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4150,7 +4150,7 @@ public Tuple(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item public TRest Rest { get { throw null; } } object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { 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; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } bool System.Collections.IStructuralEquatable.Equals(object? other, System.Collections.IEqualityComparer comparer) { throw null; } @@ -4494,7 +4494,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public const ushort MinValue = (ushort)0; public int CompareTo(object? value) { throw null; } public int CompareTo(System.UInt16 value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.UInt16 obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } @@ -4536,7 +4536,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public const uint MinValue = (uint)0; public int CompareTo(object? value) { throw null; } public int CompareTo(System.UInt32 value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.UInt32 obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } @@ -4578,7 +4578,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public const ulong MinValue = (ulong)0; public int CompareTo(object? value) { throw null; } public int CompareTo(System.UInt64 value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.UInt64 obj) { throw null; } public override int GetHashCode() { throw null; } public System.TypeCode GetTypeCode() { throw null; } @@ -4626,7 +4626,7 @@ public TypeUnloadedException(string? message, System.Exception? innerException) public static System.UIntPtr Add(System.UIntPtr pointer, int offset) { throw null; } public int CompareTo(object? value) { throw null; } public int CompareTo(System.UIntPtr value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.UIntPtr other) { throw null; } public override int GetHashCode() { throw null; } public static System.UIntPtr operator +(System.UIntPtr pointer, int offset) { throw null; } @@ -4654,8 +4654,8 @@ void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Ser public string ToString(string? format, System.IFormatProvider? provider) { throw null; } public uint ToUInt32() { throw null; } public ulong ToUInt64() { throw null; } - public static bool TryParse(string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UIntPtr result) { throw null; } - public static bool TryParse(string? s, out System.UIntPtr result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UIntPtr result) { throw null; } + public static bool TryParse([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? s, out System.UIntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, out System.UIntPtr result) { throw null; } public static bool TryParse(System.ReadOnlySpan s, System.Globalization.NumberStyles style, System.IFormatProvider? provider, out System.UIntPtr result) { throw null; } } @@ -4726,11 +4726,11 @@ public Uri(System.Uri baseUri, System.Uri relativeUri) { } [System.ObsoleteAttribute("The method has been deprecated. It is not used by the system. https://go.microsoft.com/fwlink/?linkid=14202")] protected virtual void Canonicalize() { } public static System.UriHostNameType CheckHostName(string? name) { throw null; } - public static bool CheckSchemeName(string? schemeName) { throw null; } + public static bool CheckSchemeName([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? schemeName) { throw null; } [System.ObsoleteAttribute("The method has been deprecated. It is not used by the system. https://go.microsoft.com/fwlink/?linkid=14202")] protected virtual void CheckSecurity() { } public static int Compare(System.Uri? uri1, System.Uri? uri2, System.UriComponents partsToCompare, System.UriFormat compareFormat, System.StringComparison comparisonType) { throw null; } - public override bool Equals(object? comparand) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? comparand) { throw null; } [System.ObsoleteAttribute("The method has been deprecated. It is not used by the system. https://go.microsoft.com/fwlink/?linkid=14202")] protected virtual void Escape() { } public static string EscapeDataString(string stringToEscape) { throw null; } @@ -4765,7 +4765,7 @@ protected void GetObjectData(System.Runtime.Serialization.SerializationInfo seri protected virtual void Parse() { } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { } public override string ToString() { throw null; } - public static bool TryCreate(string? uriString, System.UriKind uriKind, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Uri? result) { throw null; } + public static bool TryCreate([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? uriString, System.UriKind uriKind, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Uri? result) { throw null; } public static bool TryCreate(System.Uri? baseUri, string? relativeUri, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Uri? result) { throw null; } public static bool TryCreate(System.Uri? baseUri, System.Uri? relativeUri, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Uri? result) { throw null; } [System.ObsoleteAttribute("The method has been deprecated. Please use GetComponents() or static UnescapeDataString() to unescape a Uri component or a string. https://go.microsoft.com/fwlink/?linkid=14202")] @@ -4797,7 +4797,7 @@ public UriBuilder(System.Uri uri) { } public System.Uri Uri { get { throw null; } } [System.Diagnostics.CodeAnalysis.AllowNullAttribute] public string UserName { get { throw null; } set { } } - public override bool Equals(object? rparam) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? rparam) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -4884,7 +4884,7 @@ public partial struct ValueTuple : System.Collections.IStructuralComparable, Sys public static (T1, T2, T3, T4, T5, T6) Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6) { throw null; } public static (T1, T2, T3, T4, T5, T6, T7) Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7) { throw null; } public static (T1, T2, T3, T4, T5, T6, T7, T8) Create(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.ValueTuple other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4900,7 +4900,7 @@ public partial struct ValueTuple : System.Collections.IStructuralComparable, object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo(System.ValueTuple 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 bool Equals(System.ValueTuple other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4917,7 +4917,7 @@ public partial struct ValueTuple : System.Collections.IStructuralCompara object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2) 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 bool Equals((T1, T2) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4935,7 +4935,7 @@ public partial struct ValueTuple : System.Collections.IStructuralCom object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2, T3) 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 bool Equals((T1, T2, T3) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4954,7 +4954,7 @@ public partial struct ValueTuple : System.Collections.IStructura object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2, T3, T4) 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 bool Equals((T1, T2, T3, T4) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4974,7 +4974,7 @@ public partial struct ValueTuple : System.Collections.IStruc object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2, T3, T4, T5) 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 bool Equals((T1, T2, T3, T4, T5) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -4995,7 +4995,7 @@ public partial struct ValueTuple : System.Collections.IS object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2, T3, T4, T5, T6) 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 bool Equals((T1, T2, T3, T4, T5, T6) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -5017,7 +5017,7 @@ public partial struct ValueTuple : System.Collection object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo((T1, T2, T3, T4, T5, T6, T7) 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 bool Equals((T1, T2, T3, T4, T5, T6, T7) other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -5040,7 +5040,7 @@ public partial struct ValueTuple : System.Col object? System.Runtime.CompilerServices.ITuple.this[int index] { get { throw null; } } int System.Runtime.CompilerServices.ITuple.Length { get { throw null; } } public int CompareTo(System.ValueTuple 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 bool Equals(System.ValueTuple other) { throw null; } public override int GetHashCode() { throw null; } int System.Collections.IStructuralComparable.CompareTo(object? other, System.Collections.IComparer comparer) { throw null; } @@ -5072,7 +5072,7 @@ public Version(string version) { } public object Clone() { throw null; } public int CompareTo(object? version) { throw null; } public int CompareTo(System.Version? value) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Version? obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Version? v1, System.Version? v2) { throw null; } @@ -5636,7 +5636,7 @@ public DefaultValueAttribute(uint value) { } [System.CLSCompliantAttribute(false)] public DefaultValueAttribute(ulong value) { } public virtual object? Value { get { 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; } protected void SetValue(object? value) { } } @@ -5646,7 +5646,7 @@ public sealed partial class EditorBrowsableAttribute : System.Attribute public EditorBrowsableAttribute() { } public EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState state) { } public System.ComponentModel.EditorBrowsableState State { get { 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 enum EditorBrowsableState @@ -6115,7 +6115,7 @@ internal CompareInfo() { } public int Compare(string? string1, int offset1, string? string2, int offset2, System.Globalization.CompareOptions options) { throw null; } public int Compare(string? string1, string? string2) { throw null; } public int Compare(string? string1, string? string2, System.Globalization.CompareOptions options) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public static System.Globalization.CompareInfo GetCompareInfo(int culture) { throw null; } public static System.Globalization.CompareInfo GetCompareInfo(int culture, System.Reflection.Assembly assembly) { throw null; } public static System.Globalization.CompareInfo GetCompareInfo(string name) { throw null; } @@ -6221,7 +6221,7 @@ public CultureInfo(string name, bool useUserOverride) { } public void ClearCachedData() { } public virtual object Clone() { throw null; } public static System.Globalization.CultureInfo CreateSpecificCulture(string name) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public System.Globalization.CultureInfo GetConsoleFallbackUICulture() { throw null; } public static System.Globalization.CultureInfo GetCultureInfo(int culture) { throw null; } public static System.Globalization.CultureInfo GetCultureInfo(string name) { throw null; } @@ -6466,7 +6466,7 @@ public sealed partial class IdnMapping public IdnMapping() { } public bool AllowUnassigned { get { throw null; } set { } } public bool UseStd3AsciiRules { get { throw null; } set { } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public string GetAscii(string unicode) { throw null; } public string GetAscii(string unicode, int index) { throw null; } public string GetAscii(string unicode, int index, int count) { throw null; } @@ -6690,7 +6690,7 @@ public RegionInfo(string name) { } public virtual string ThreeLetterISORegionName { get { throw null; } } public virtual string ThreeLetterWindowsRegionName { get { throw null; } } public virtual string TwoLetterISORegionName { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -6700,7 +6700,7 @@ internal SortKey() { } public byte[] KeyData { get { throw null; } } public string OriginalString { get { throw null; } } public static int Compare(System.Globalization.SortKey sortkey1, System.Globalization.SortKey sortkey2) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } } @@ -6710,7 +6710,7 @@ public SortVersion(int fullVersion, System.Guid sortId) { } public int FullVersion { get { throw null; } } public System.Guid SortId { get { throw null; } } public bool Equals(System.Globalization.SortVersion? 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 ==(System.Globalization.SortVersion? left, System.Globalization.SortVersion? right) { throw null; } public static bool operator !=(System.Globalization.SortVersion? left, System.Globalization.SortVersion? right) { throw null; } @@ -6721,7 +6721,7 @@ public StringInfo() { } public StringInfo(string value) { } public int LengthInTextElements { get { throw null; } } public string String { get { throw null; } set { } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } public static string GetNextTextElement(string str) { throw null; } public static string GetNextTextElement(string str, int index) { throw null; } @@ -6792,7 +6792,7 @@ internal TextInfo() { } public int MacCodePage { get { throw null; } } public int OEMCodePage { get { throw null; } } public object Clone() { 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 System.Globalization.TextInfo ReadOnly(System.Globalization.TextInfo textInfo) { throw null; } void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { } @@ -7270,7 +7270,7 @@ public static partial class Path public static string GetTempFileName() { throw null; } public static string GetTempPath() { throw null; } public static bool HasExtension(System.ReadOnlySpan path) { throw null; } - public static bool HasExtension(string? path) { throw null; } + public static bool HasExtension([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? path) { throw null; } public static bool IsPathFullyQualified(System.ReadOnlySpan path) { throw null; } public static bool IsPathFullyQualified(string path) { throw null; } public static bool IsPathRooted(System.ReadOnlySpan path) { throw null; } @@ -9785,7 +9785,7 @@ public partial struct GCHandle public System.IntPtr AddrOfPinnedObject() { throw null; } public static System.Runtime.InteropServices.GCHandle Alloc(object? value) { throw null; } public static System.Runtime.InteropServices.GCHandle Alloc(object? value, System.Runtime.InteropServices.GCHandleType type) { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public void Free() { } public static System.Runtime.InteropServices.GCHandle FromIntPtr(System.IntPtr value) { throw null; } public override int GetHashCode() { throw null; } @@ -10046,7 +10046,7 @@ public readonly partial struct StreamingContext public StreamingContext(System.Runtime.Serialization.StreamingContextStates state, object? additional) { throw null; } public object? Context { get { throw null; } } public System.Runtime.Serialization.StreamingContextStates State { get { 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; } } [System.FlagsAttribute] @@ -10088,7 +10088,7 @@ public FrameworkName(string identifier, System.Version version, string? profile) public string Identifier { get { throw null; } } public string Profile { get { throw null; } } public System.Version Version { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Runtime.Versioning.FrameworkName? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Runtime.Versioning.FrameworkName? left, System.Runtime.Versioning.FrameworkName? right) { throw null; } @@ -10258,13 +10258,13 @@ public void AddAttribute(string name, string value) { } public void AddChild(System.Security.SecurityElement child) { } public string? Attribute(string name) { throw null; } public System.Security.SecurityElement Copy() { throw null; } - public bool Equal(System.Security.SecurityElement? other) { throw null; } + public bool Equal([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.SecurityElement? other) { throw null; } public static string? Escape(string? str) { throw null; } public static System.Security.SecurityElement? FromString(string xml) { throw null; } - public static bool IsValidAttributeName(string? name) { throw null; } - public static bool IsValidAttributeValue(string? value) { throw null; } - public static bool IsValidTag(string? tag) { throw null; } - public static bool IsValidText(string? text) { throw null; } + public static bool IsValidAttributeName([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? name) { throw null; } + public static bool IsValidAttributeValue([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? value) { throw null; } + public static bool IsValidTag([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? tag) { throw null; } + public static bool IsValidText([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? text) { throw null; } public System.Security.SecurityElement? SearchForChildByTag(string tag) { throw null; } public string? SearchForTextOfTag(string tag) { throw null; } public override string ToString() { throw null; } @@ -10485,7 +10485,7 @@ public sealed partial class DecoderExceptionFallback : System.Text.DecoderFallba public DecoderExceptionFallback() { } public override int MaxCharCount { get { throw null; } } public override System.Text.DecoderFallbackBuffer CreateFallbackBuffer() { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } } public sealed partial class DecoderExceptionFallbackBuffer : System.Text.DecoderFallbackBuffer @@ -10529,7 +10529,7 @@ public DecoderReplacementFallback(string replacement) { } public string DefaultString { get { throw null; } } public override int MaxCharCount { get { throw null; } } public override System.Text.DecoderFallbackBuffer CreateFallbackBuffer() { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } } public sealed partial class DecoderReplacementFallbackBuffer : System.Text.DecoderFallbackBuffer @@ -10565,7 +10565,7 @@ public sealed partial class EncoderExceptionFallback : System.Text.EncoderFallba public EncoderExceptionFallback() { } public override int MaxCharCount { get { throw null; } } public override System.Text.EncoderFallbackBuffer CreateFallbackBuffer() { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } } public sealed partial class EncoderExceptionFallbackBuffer : System.Text.EncoderFallbackBuffer @@ -10613,7 +10613,7 @@ public EncoderReplacementFallback(string replacement) { } public string DefaultString { get { throw null; } } public override int MaxCharCount { get { throw null; } } public override System.Text.EncoderFallbackBuffer CreateFallbackBuffer() { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public override int GetHashCode() { throw null; } } public sealed partial class EncoderReplacementFallbackBuffer : System.Text.EncoderFallbackBuffer @@ -10659,7 +10659,7 @@ protected Encoding(int codePage, System.Text.EncoderFallback? encoderFallback, S public static byte[] Convert(System.Text.Encoding srcEncoding, System.Text.Encoding dstEncoding, byte[] bytes) { throw null; } public static byte[] Convert(System.Text.Encoding srcEncoding, System.Text.Encoding dstEncoding, byte[] bytes, int index, int count) { throw null; } public static System.IO.Stream CreateTranscodingStream(System.IO.Stream innerStream, System.Text.Encoding innerStreamEncoding, System.Text.Encoding outerStreamEncoding, bool leaveOpen = false) { throw null; } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } [System.CLSCompliantAttribute(false)] public unsafe virtual int GetByteCount(char* chars, int count) { throw null; } public virtual int GetByteCount(char[] chars) { throw null; } @@ -10713,7 +10713,7 @@ public EncodingInfo(System.Text.EncodingProvider provider, int codePage, string public int CodePage { get { throw null; } } public string DisplayName { get { throw null; } } public string Name { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } public System.Text.Encoding GetEncoding() { throw null; } public override int GetHashCode() { throw null; } } @@ -10755,7 +10755,7 @@ public enum NormalizationForm public static System.Buffers.OperationStatus DecodeLastFromUtf8(System.ReadOnlySpan source, out System.Text.Rune value, out int bytesConsumed) { throw null; } public int EncodeToUtf16(System.Span destination) { throw null; } public int EncodeToUtf8(System.Span destination) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Text.Rune other) { throw null; } public override int GetHashCode() { throw null; } public static double GetNumericValue(System.Text.Rune value) { throw null; } @@ -10863,7 +10863,7 @@ public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, in public void CopyTo(int sourceIndex, System.Span destination, int count) { } public int EnsureCapacity(int capacity) { throw null; } public bool Equals(System.ReadOnlySpan span) { throw null; } - public bool Equals(System.Text.StringBuilder? sb) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Text.StringBuilder? sb) { throw null; } public System.Text.StringBuilder.ChunkEnumerator GetChunks() { throw null; } public System.Text.StringBuilder Insert(int index, bool value) { throw null; } public System.Text.StringBuilder Insert(int index, byte value) { throw null; } @@ -10939,7 +10939,7 @@ public readonly partial struct CancellationToken public bool IsCancellationRequested { get { throw null; } } public static System.Threading.CancellationToken None { get { throw null; } } public System.Threading.WaitHandle WaitHandle { get { throw null; } } - public override bool Equals(object? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? other) { throw null; } public bool Equals(System.Threading.CancellationToken other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Threading.CancellationToken left, System.Threading.CancellationToken right) { throw null; } @@ -10960,7 +10960,7 @@ public void ThrowIfCancellationRequested() { } public System.Threading.CancellationToken Token { get { throw null; } } public void Dispose() { } public System.Threading.Tasks.ValueTask DisposeAsync() { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.CancellationTokenRegistration other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Threading.CancellationTokenRegistration left, System.Threading.CancellationTokenRegistration right) { throw null; } @@ -11471,7 +11471,7 @@ public void SetObserved() { } public bool IsFaulted { get { throw null; } } public System.Threading.Tasks.Task AsTask() { throw null; } public System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.Tasks.ValueTask other) { throw null; } public static System.Threading.Tasks.ValueTask FromCanceled(System.Threading.CancellationToken cancellationToken) { throw null; } public static System.Threading.Tasks.ValueTask FromCanceled(System.Threading.CancellationToken cancellationToken) { throw null; } @@ -11500,7 +11500,7 @@ public void SetObserved() { } public TResult Result { get { throw null; } } public System.Threading.Tasks.Task AsTask() { throw null; } public System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable ConfigureAwait(bool continueOnCapturedContext) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.Tasks.ValueTask other) { throw null; } public System.Runtime.CompilerServices.ValueTaskAwaiter GetAwaiter() { throw null; } public override int GetHashCode() { throw null; } diff --git a/src/libraries/System.Security.AccessControl/ref/System.Security.AccessControl.cs b/src/libraries/System.Security.AccessControl/ref/System.Security.AccessControl.cs index e3738ad9658f8..b47ecfdc10165 100644 --- a/src/libraries/System.Security.AccessControl/ref/System.Security.AccessControl.cs +++ b/src/libraries/System.Security.AccessControl/ref/System.Security.AccessControl.cs @@ -270,7 +270,7 @@ internal GenericAce() { } public System.Security.AccessControl.PropagationFlags PropagationFlags { get { throw null; } } public System.Security.AccessControl.GenericAce Copy() { throw null; } public static System.Security.AccessControl.GenericAce CreateFromBinaryForm(byte[] binaryForm, int offset) { throw null; } - public sealed override bool Equals(object? o) { throw null; } + public sealed override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public abstract void GetBinaryForm(byte[] binaryForm, int offset); public sealed override int GetHashCode() { throw null; } public static bool operator ==(System.Security.AccessControl.GenericAce? left, System.Security.AccessControl.GenericAce? right) { throw null; } diff --git a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs index 6f632645f0ea5..2dafddc3128e5 100644 --- a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs +++ b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs @@ -537,7 +537,7 @@ public GenericAce Copy() return GenericAce.CreateFromBinaryForm(binaryForm, 0); } - public sealed override bool Equals(object? o) + public sealed override bool Equals([NotNullWhen(true)] object? o) { GenericAce? ace = (o as GenericAce); diff --git a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs index e4fbe5036796e..60066df503fc9 100644 --- a/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs +++ b/src/libraries/System.Security.Claims/ref/System.Security.Claims.cs @@ -210,6 +210,6 @@ public partial class GenericPrincipal : System.Security.Claims.ClaimsPrincipal { public GenericPrincipal(System.Security.Principal.IIdentity identity, string[]? roles) { } public override System.Security.Principal.IIdentity Identity { get { throw null; } } - public override bool IsInRole(string? role) { throw null; } + public override bool IsInRole([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] string? role) { throw null; } } } diff --git a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs index 51e79cdf0db51..ed11066aed5de 100644 --- a/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs +++ b/src/libraries/System.Security.Claims/src/System/Security/Claims/GenericPrincipal.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Security.Claims; namespace System.Security.Principal @@ -67,7 +68,7 @@ public override IIdentity Identity get { return m_identity; } } - public override bool IsInRole(string? role) + public override bool IsInRole([NotNullWhen(true)] string? role) { if (role == null || m_roles == null) return false; diff --git a/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs b/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs index 12d2b8700fc14..8e9d12de19a4e 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/ref/System.Security.Cryptography.Algorithms.cs @@ -686,7 +686,7 @@ internal RSAEncryptionPadding() { } public static System.Security.Cryptography.RSAEncryptionPadding Pkcs1 { get { throw null; } } public static System.Security.Cryptography.RSAEncryptionPadding CreateOaep(System.Security.Cryptography.HashAlgorithmName hashAlgorithm) { throw null; } public override bool Equals(object? obj) { throw null; } - public bool Equals(System.Security.Cryptography.RSAEncryptionPadding? other) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.RSAEncryptionPadding? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Security.Cryptography.RSAEncryptionPadding? left, System.Security.Cryptography.RSAEncryptionPadding? right) { throw null; } public static bool operator !=(System.Security.Cryptography.RSAEncryptionPadding? left, System.Security.Cryptography.RSAEncryptionPadding? right) { throw null; } @@ -775,7 +775,7 @@ internal RSASignaturePadding() { } public System.Security.Cryptography.RSASignaturePaddingMode Mode { get { throw null; } } public static System.Security.Cryptography.RSASignaturePadding Pkcs1 { get { throw null; } } public static System.Security.Cryptography.RSASignaturePadding Pss { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Security.Cryptography.RSASignaturePadding? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Security.Cryptography.RSASignaturePadding? left, System.Security.Cryptography.RSASignaturePadding? right) { throw null; } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs index 90ad6fe9a48ce..ae356492bcec0 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.Versioning; namespace System.Security.Cryptography @@ -95,12 +96,12 @@ private static int CombineHashCodes(int h1, int h2) return (((h1 << 5) + h1) ^ h2); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as RSAEncryptionPadding); } - public bool Equals(RSAEncryptionPadding? other) + public bool Equals([NotNullWhen(true)] RSAEncryptionPadding? other) { return other is not null && _mode == other._mode diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs index de0f413440d25..82b37d63c799d 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.Versioning; namespace System.Security.Cryptography @@ -54,12 +55,12 @@ public override int GetHashCode() return _mode.GetHashCode(); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return Equals(obj as RSASignaturePadding); } - public bool Equals(RSASignaturePadding? other) + public bool Equals([NotNullWhen(true)] RSASignaturePadding? other) { return other is not null && _mode == other._mode; } diff --git a/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs b/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs index 97fbd6c4efbb2..15eea497ef671 100644 --- a/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs +++ b/src/libraries/System.Security.Cryptography.Cng/ref/System.Security.Cryptography.Cng.cs @@ -67,8 +67,8 @@ public CngAlgorithm(string algorithm) { } public static System.Security.Cryptography.CngAlgorithm Sha256 { get { throw null; } } public static System.Security.Cryptography.CngAlgorithm Sha384 { get { throw null; } } public static System.Security.Cryptography.CngAlgorithm Sha512 { get { throw null; } } - public override bool Equals(object? obj) { throw null; } - public bool Equals(System.Security.Cryptography.CngAlgorithm? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.CngAlgorithm? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Security.Cryptography.CngAlgorithm? left, System.Security.Cryptography.CngAlgorithm? right) { throw null; } public static bool operator !=(System.Security.Cryptography.CngAlgorithm? left, System.Security.Cryptography.CngAlgorithm? right) { throw null; } @@ -83,8 +83,8 @@ public CngAlgorithmGroup(string algorithmGroup) { } public static System.Security.Cryptography.CngAlgorithmGroup ECDiffieHellman { get { throw null; } } public static System.Security.Cryptography.CngAlgorithmGroup ECDsa { get { throw null; } } public static System.Security.Cryptography.CngAlgorithmGroup Rsa { get { throw null; } } - public override bool Equals(object? obj) { throw null; } - public bool Equals(System.Security.Cryptography.CngAlgorithmGroup? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.CngAlgorithmGroup? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Security.Cryptography.CngAlgorithmGroup? left, System.Security.Cryptography.CngAlgorithmGroup? right) { throw null; } public static bool operator !=(System.Security.Cryptography.CngAlgorithmGroup? left, System.Security.Cryptography.CngAlgorithmGroup? right) { throw null; } @@ -148,7 +148,7 @@ public CngKeyBlobFormat(string format) { } public static System.Security.Cryptography.CngKeyBlobFormat OpaqueTransportBlob { get { throw null; } } public static System.Security.Cryptography.CngKeyBlobFormat Pkcs8PrivateBlob { get { throw null; } } public override bool Equals(object? obj) { throw null; } - public bool Equals(System.Security.Cryptography.CngKeyBlobFormat? other) { throw null; } + public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.CngKeyBlobFormat? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Security.Cryptography.CngKeyBlobFormat? left, System.Security.Cryptography.CngKeyBlobFormat? right) { throw null; } public static bool operator !=(System.Security.Cryptography.CngKeyBlobFormat? left, System.Security.Cryptography.CngKeyBlobFormat? right) { throw null; } @@ -202,7 +202,7 @@ public partial struct CngProperty : System.IEquatable public CngPropertyOptions Options { get; private set; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is CngProperty && Equals((CngProperty)obj); } diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs index 3547b0f429ae9..939afe67e8663 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace System.Security.Cryptography { @@ -53,14 +54,14 @@ public string Provider return !left.Equals(right); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { Debug.Assert(_provider != null); return Equals(obj as CngProvider); } - public bool Equals(CngProvider? other) + public bool Equals([NotNullWhen(true)] CngProvider? other) { if (other is null) { diff --git a/src/libraries/System.Security.Cryptography.Primitives/ref/System.Security.Cryptography.Primitives.cs b/src/libraries/System.Security.Cryptography.Primitives/ref/System.Security.Cryptography.Primitives.cs index dbe106511bcdb..4bb8924715d96 100644 --- a/src/libraries/System.Security.Cryptography.Primitives/ref/System.Security.Cryptography.Primitives.cs +++ b/src/libraries/System.Security.Cryptography.Primitives/ref/System.Security.Cryptography.Primitives.cs @@ -139,7 +139,7 @@ protected virtual void HashCore(System.ReadOnlySpan source) { } public static System.Security.Cryptography.HashAlgorithmName SHA256 { get { throw null; } } public static System.Security.Cryptography.HashAlgorithmName SHA384 { get { throw null; } } public static System.Security.Cryptography.HashAlgorithmName SHA512 { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Security.Cryptography.HashAlgorithmName other) { throw null; } public static System.Security.Cryptography.HashAlgorithmName FromOid(string oidValue) { throw null; } public override int GetHashCode() { throw null; } diff --git a/src/libraries/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithmName.cs b/src/libraries/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithmName.cs index 1c9c95904ebc1..07e332f82f384 100644 --- a/src/libraries/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithmName.cs +++ b/src/libraries/System.Security.Cryptography.Primitives/src/System/Security/Cryptography/HashAlgorithmName.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 System.Security.Cryptography { // Strongly typed string representing the name of a hash algorithm. @@ -78,7 +80,7 @@ public override string ToString() return _name ?? string.Empty; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is HashAlgorithmName && Equals((HashAlgorithmName)obj); } diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/ref/System.Security.Cryptography.X509Certificates.cs b/src/libraries/System.Security.Cryptography.X509Certificates/ref/System.Security.Cryptography.X509Certificates.cs index 8f5f7253b6b6a..992d44d0824b9 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/ref/System.Security.Cryptography.X509Certificates.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/ref/System.Security.Cryptography.X509Certificates.cs @@ -162,8 +162,8 @@ public X509Certificate(string fileName, string? password, System.Security.Crypto public static System.Security.Cryptography.X509Certificates.X509Certificate CreateFromSignedFile(string filename) { throw null; } public void Dispose() { } protected virtual void Dispose(bool disposing) { } - public override bool Equals(object? obj) { throw null; } - public virtual bool Equals(System.Security.Cryptography.X509Certificates.X509Certificate? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } + public virtual bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Security.Cryptography.X509Certificates.X509Certificate? other) { throw null; } public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType) { throw null; } [System.CLSCompliantAttribute(false)] public virtual byte[] Export(System.Security.Cryptography.X509Certificates.X509ContentType contentType, System.Security.SecureString? password) { throw null; } diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs index 6770a830f5f5b..f414305bc0782 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/X509Certificate.cs @@ -5,6 +5,7 @@ using Internal.Cryptography.Pal; using Microsoft.Win32.SafeHandles; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.Serialization; using System.Text; @@ -269,7 +270,7 @@ protected virtual void Dispose(bool disposing) } } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { X509Certificate? other = obj as X509Certificate; if (other == null) @@ -277,7 +278,7 @@ public override bool Equals(object? obj) return Equals(other); } - public virtual bool Equals(X509Certificate? other) + public virtual bool Equals([NotNullWhen(true)] X509Certificate? other) { if (other == null) return false; diff --git a/src/libraries/System.Security.Principal.Windows/ref/System.Security.Principal.Windows.cs b/src/libraries/System.Security.Principal.Windows/ref/System.Security.Principal.Windows.cs index 5daebe3b72ab7..36dfeefbb7e15 100644 --- a/src/libraries/System.Security.Principal.Windows/ref/System.Security.Principal.Windows.cs +++ b/src/libraries/System.Security.Principal.Windows/ref/System.Security.Principal.Windows.cs @@ -59,7 +59,7 @@ public sealed partial class NTAccount : System.Security.Principal.IdentityRefere public NTAccount(string name) { } public NTAccount(string domainName, string accountName) { } public override string Value { get { throw null; } } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public override bool IsValidTargetType(System.Type targetType) { throw null; } public static bool operator ==(System.Security.Principal.NTAccount? left, System.Security.Principal.NTAccount? right) { throw null; } @@ -79,7 +79,7 @@ public SecurityIdentifier(string sddlForm) { } public int BinaryLength { get { throw null; } } public override string Value { get { throw null; } } public int CompareTo(System.Security.Principal.SecurityIdentifier? sid) { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public bool Equals(System.Security.Principal.SecurityIdentifier sid) { throw null; } public void GetBinaryForm(byte[] binaryForm, int offset) { } public override int GetHashCode() { throw null; } diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs index 88d64de715cc6..345e54f808b2f 100644 --- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs +++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/NTAccount.cs @@ -5,6 +5,7 @@ using Microsoft.Win32.SafeHandles; using System.ComponentModel; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.InteropServices; @@ -136,7 +137,7 @@ public override IdentityReference Translate(Type targetType) } } - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { return (this == o as NTAccount); // invokes operator== } diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs index 235bb8c1c28df..1291a1f42fa69 100644 --- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs +++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs @@ -719,7 +719,7 @@ public SecurityIdentifier? AccountDomainSid #region Inherited properties and methods - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { return (this == o as SecurityIdentifier); // invokes operator== } diff --git a/src/libraries/System.ServiceProcess.ServiceController/ref/System.ServiceProcess.ServiceController.cs b/src/libraries/System.ServiceProcess.ServiceController/ref/System.ServiceProcess.ServiceController.cs index 8fc328bf373d0..5846cec5477c9 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/ref/System.ServiceProcess.ServiceController.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/ref/System.ServiceProcess.ServiceController.cs @@ -131,7 +131,7 @@ public readonly partial struct SessionChangeDescription private readonly int _dummyPrimitive; public System.ServiceProcess.SessionChangeReason Reason { get { throw null; } } public int SessionId { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.ServiceProcess.SessionChangeDescription changeDescription) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.ServiceProcess.SessionChangeDescription a, System.ServiceProcess.SessionChangeDescription b) { throw null; } diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/SessionChangeDescription.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/SessionChangeDescription.cs index 449b2cc1939e4..bc11eaeea1091 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/SessionChangeDescription.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/SessionChangeDescription.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 System.ServiceProcess { public readonly struct SessionChangeDescription @@ -15,7 +17,7 @@ internal SessionChangeDescription(SessionChangeReason reason, int id) public int SessionId { get; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is SessionChangeDescription)) { diff --git a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderBestFitFallback.cs b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderBestFitFallback.cs index 11e3c63e2f5c8..be1e202b05779 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderBestFitFallback.cs +++ b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/DecoderBestFitFallback.cs @@ -6,9 +6,10 @@ // using System; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text; using System.Threading; -using System.Diagnostics; namespace System.Text { @@ -31,7 +32,7 @@ public override DecoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => 1; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is InternalDecoderBestFitFallback that && encoding.CodePage == that.encoding.CodePage; public override int GetHashCode() => encoding.CodePage; diff --git a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderBestFitFallback.cs b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderBestFitFallback.cs index 3ae2e081079a6..3c42ac90761ea 100644 --- a/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderBestFitFallback.cs +++ b/src/libraries/System.Text.Encoding.CodePages/src/System/Text/EncoderBestFitFallback.cs @@ -7,6 +7,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Text; using System.Threading; @@ -31,7 +32,7 @@ public override EncoderFallbackBuffer CreateFallbackBuffer() => // Maximum number of characters that this instance of this fallback could return public override int MaxCharCount => 1; - public override bool Equals(object? value) => + public override bool Equals([NotNullWhen(true)] object? value) => value is InternalEncoderBestFitFallback that && encoding.CodePage == that.encoding.CodePage; public override int GetHashCode() => encoding.CodePage; diff --git a/src/libraries/System.Text.Encoding.Extensions/ref/System.Text.Encoding.Extensions.cs b/src/libraries/System.Text.Encoding.Extensions/ref/System.Text.Encoding.Extensions.cs index 834158f0b94c0..a13aedd4f5733 100644 --- a/src/libraries/System.Text.Encoding.Extensions/ref/System.Text.Encoding.Extensions.cs +++ b/src/libraries/System.Text.Encoding.Extensions/ref/System.Text.Encoding.Extensions.cs @@ -41,7 +41,7 @@ public UnicodeEncoding() { } public UnicodeEncoding(bool bigEndian, bool byteOrderMark) { } public UnicodeEncoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes) { } public override System.ReadOnlySpan Preamble { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } [System.CLSCompliantAttribute(false)] public unsafe override int GetByteCount(char* chars, int count) { throw null; } public override int GetByteCount(char[] chars, int index, int count) { throw null; } @@ -70,7 +70,7 @@ public UTF32Encoding() { } public UTF32Encoding(bool bigEndian, bool byteOrderMark) { } public UTF32Encoding(bool bigEndian, bool byteOrderMark, bool throwOnInvalidCharacters) { } public override System.ReadOnlySpan Preamble { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } [System.CLSCompliantAttribute(false)] public unsafe override int GetByteCount(char* chars, int count) { throw null; } public override int GetByteCount(char[] chars, int index, int count) { throw null; } @@ -99,7 +99,7 @@ public partial class UTF7Encoding : System.Text.Encoding public UTF7Encoding() { } [System.ObsoleteAttribute("The UTF-7 encoding is insecure and should not be used. Consider using UTF-8 instead.", DiagnosticId = "SYSLIB0001", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] public UTF7Encoding(bool allowOptionals) { } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } [System.CLSCompliantAttribute(false)] public unsafe override int GetByteCount(char* chars, int count) { throw null; } public override int GetByteCount(char[] chars, int index, int count) { throw null; } @@ -127,7 +127,7 @@ public UTF8Encoding() { } public UTF8Encoding(bool encoderShouldEmitUTF8Identifier) { } public UTF8Encoding(bool encoderShouldEmitUTF8Identifier, bool throwOnInvalidBytes) { } public override System.ReadOnlySpan Preamble { get { throw null; } } - public override bool Equals(object? value) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; } [System.CLSCompliantAttribute(false)] public unsafe override int GetByteCount(char* chars, int count) { throw null; } public override int GetByteCount(char[] chars, int index, int count) { throw null; } diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.cs b/src/libraries/System.Text.Json/ref/System.Text.Json.cs index a70874667f20f..3923f96036c62 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.cs +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.cs @@ -133,7 +133,7 @@ public void Reset() { } public static System.Text.Json.JsonEncodedText Encode(System.ReadOnlySpan utf8Value, System.Text.Encodings.Web.JavaScriptEncoder? encoder = null) { throw null; } public static System.Text.Json.JsonEncodedText Encode(System.ReadOnlySpan value, System.Text.Encodings.Web.JavaScriptEncoder? encoder = null) { throw null; } public static System.Text.Json.JsonEncodedText Encode(string value, System.Text.Encodings.Web.JavaScriptEncoder? encoder = null) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Text.Json.JsonEncodedText other) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs index 660bf22dbe661..54baa8940333b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonEncodedText.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Text.Encodings.Web; namespace System.Text.Json @@ -148,7 +149,7 @@ public bool Equals(JsonEncodedText other) /// /// If is null, the method returns false. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj is JsonEncodedText encodedText) { diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs index 8f2f195517ecb..6919995dd5072 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonClassInfo.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Text.Json.Serialization; @@ -305,7 +306,7 @@ public override int GetHashCode() return StringComparer.OrdinalIgnoreCase.GetHashCode(Name); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { Debug.Assert(obj is ParameterLookupKey); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Cache.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Cache.cs index 5ba43c3a5ca06..af0251ca788fd 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Cache.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Cache.cs @@ -278,7 +278,7 @@ public Key(string pattern, string culture, RegexOptions options, bool hasTimeout _hasTimeout = hasTimeout; } - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is Key other && Equals(other); public bool Equals(Key other) => diff --git a/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs b/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs index 4931e851d6d39..d3ec40ccc0034 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/ref/System.Threading.Tasks.Dataflow.cs @@ -163,7 +163,7 @@ public DataflowLinkOptions() { } public DataflowMessageHeader(long id) { throw null; } public long Id { get { throw null; } } public bool IsValid { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.Tasks.Dataflow.DataflowMessageHeader other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Threading.Tasks.Dataflow.DataflowMessageHeader left, System.Threading.Tasks.Dataflow.DataflowMessageHeader right) { throw null; } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowMessageHeader.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowMessageHeader.cs index dde0b4ad4df7a..d55a20be243bc 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowMessageHeader.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Base/DataflowMessageHeader.cs @@ -11,6 +11,7 @@ // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks.Dataflow.Internal; namespace System.Threading.Tasks.Dataflow @@ -56,7 +57,7 @@ public bool Equals(DataflowMessageHeader other) /// Checks boxed instances for equality by ID. /// A boxed instance. /// True if the instances are equal. False otherwise. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is DataflowMessageHeader && this == (DataflowMessageHeader)obj; } diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index f25070b0279e9..c05b76130234b 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -23,7 +23,7 @@ public partial struct AsyncFlowControl : System.IEquatable, Sy private object _dummy; private int _dummyPrimitive; public void Dispose() { } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.AsyncFlowControl obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Threading.AsyncFlowControl a, System.Threading.AsyncFlowControl b) { throw null; } @@ -238,7 +238,7 @@ public static partial class LazyInitializer public partial struct LockCookie { private int _dummyPrimitive; - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public bool Equals(System.Threading.LockCookie obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Threading.LockCookie a, System.Threading.LockCookie b) { throw null; } diff --git a/src/libraries/System.Threading/src/System/Threading/LockCookie.cs b/src/libraries/System.Threading/src/System/Threading/LockCookie.cs index 3e96a601b92ca..6a76ceb023d0a 100644 --- a/src/libraries/System.Threading/src/System/Threading/LockCookie.cs +++ b/src/libraries/System.Threading/src/System/Threading/LockCookie.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 System.Threading { /// @@ -19,7 +21,7 @@ public override int GetHashCode() return (int)_flags + _readerLevel + _writerLevel + _threadID; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is LockCookie && Equals((LockCookie)obj); } diff --git a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs index 9520218380b23..91804388b42fa 100644 --- a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs +++ b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs @@ -128,7 +128,7 @@ public void Dispose() { } public bool EnlistPromotableSinglePhase(System.Transactions.IPromotableSinglePhaseNotification promotableSinglePhaseNotification, System.Guid promoterType) { throw null; } public System.Transactions.Enlistment EnlistVolatile(System.Transactions.IEnlistmentNotification enlistmentNotification, System.Transactions.EnlistmentOptions enlistmentOptions) { throw null; } public System.Transactions.Enlistment EnlistVolatile(System.Transactions.ISinglePhaseNotification singlePhaseNotification, System.Transactions.EnlistmentOptions enlistmentOptions) { 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 byte[] GetPromotedToken() { throw null; } public static bool operator ==(System.Transactions.Transaction? x, System.Transactions.Transaction? y) { throw null; } @@ -207,7 +207,7 @@ public partial struct TransactionOptions private int _dummyPrimitive; public System.Transactions.IsolationLevel IsolationLevel { get { throw null; } set { } } public System.TimeSpan Timeout { get { throw null; } set { } } - 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 ==(System.Transactions.TransactionOptions x, System.Transactions.TransactionOptions y) { throw null; } public static bool operator !=(System.Transactions.TransactionOptions x, System.Transactions.TransactionOptions y) { throw null; } diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs index f925c15ce7c32..523cc4cf82485 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.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 System.Transactions { /// @@ -46,7 +48,7 @@ public EnlistmentTraceIdentifier( public override int GetHashCode() => base.GetHashCode(); // Don't have anything better to do. - public override bool Equals(object? obj) => obj is EnlistmentTraceIdentifier enlistmentTraceId && Equals(enlistmentTraceId); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is EnlistmentTraceIdentifier enlistmentTraceId && Equals(enlistmentTraceId); public bool Equals(EnlistmentTraceIdentifier other) => _enlistmentIdentifier == other._enlistmentIdentifier && diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs index 3851ed0c53ccc..136e664ab929c 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/Transaction.cs @@ -319,7 +319,7 @@ public override int GetHashCode() // Don't allow equals to get the identifier // - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { // If we can't cast the object as a Transaction, it must not be equal // to this, which is a Transaction. Check the internal transaction object for equality. diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionOptions.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionOptions.cs index 767b421044713..1fa34283bb455 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionOptions.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionOptions.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 System.Transactions { public struct TransactionOptions @@ -22,7 +24,7 @@ public IsolationLevel IsolationLevel public override int GetHashCode() => base.GetHashCode(); // Don't have anything better to do. - public override bool Equals(object? obj) => obj is TransactionOptions transactionOptions && Equals(transactionOptions); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is TransactionOptions transactionOptions && Equals(transactionOptions); private bool Equals(TransactionOptions other) => _timeout == other._timeout && diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs index 534419bd9cc79..3546ed4b5bf95 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.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 System.Transactions { /// @@ -33,7 +35,7 @@ public TransactionTraceIdentifier(string transactionIdentifier, int cloneIdentif public override int GetHashCode() => base.GetHashCode(); // Don't have anything better to do. - public override bool Equals(object? obj) => obj is TransactionTraceIdentifier transactionTraceId && Equals(transactionTraceId); + public override bool Equals([NotNullWhen(true)] object? obj) => obj is TransactionTraceIdentifier transactionTraceId && Equals(transactionTraceId); public bool Equals(TransactionTraceIdentifier other) => _cloneIdentifier == other._cloneIdentifier && diff --git a/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs b/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs index f755ab0e3db91..01cedbb200edd 100644 --- a/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs +++ b/src/libraries/System.Xml.ReaderWriter/ref/System.Xml.ReaderWriter.cs @@ -760,7 +760,7 @@ public XmlQualifiedName(string? name, string? ns) { } public bool IsEmpty { get { throw null; } } public string Name { get { throw null; } } public string Namespace { get { throw null; } } - public override bool Equals(object? other) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? other) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Xml.XmlQualifiedName? a, System.Xml.XmlQualifiedName? b) { throw null; } public static bool operator !=(System.Xml.XmlQualifiedName? a, System.Xml.XmlQualifiedName? b) { throw null; } @@ -2292,7 +2292,7 @@ public XmlSchemaType() { } public static System.Xml.Schema.XmlSchemaComplexType? GetBuiltInComplexType(System.Xml.XmlQualifiedName qualifiedName) { throw null; } public static System.Xml.Schema.XmlSchemaSimpleType GetBuiltInSimpleType(System.Xml.Schema.XmlTypeCode typeCode) { throw null; } public static System.Xml.Schema.XmlSchemaSimpleType? GetBuiltInSimpleType(System.Xml.XmlQualifiedName qualifiedName) { throw null; } - public static bool IsDerivedFrom(System.Xml.Schema.XmlSchemaType? derivedType, System.Xml.Schema.XmlSchemaType? baseType, System.Xml.Schema.XmlSchemaDerivationMethod except) { throw null; } + public static bool IsDerivedFrom([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Xml.Schema.XmlSchemaType? derivedType, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.Xml.Schema.XmlSchemaType? baseType, System.Xml.Schema.XmlSchemaDerivationMethod except) { throw null; } } public partial class XmlSchemaUnique : System.Xml.Schema.XmlSchemaIdentityConstraint { diff --git a/src/libraries/System.Xml.XDocument/ref/System.Xml.XDocument.cs b/src/libraries/System.Xml.XDocument/ref/System.Xml.XDocument.cs index 2e03c245bb4e3..f9fd0e20fbaeb 100644 --- a/src/libraries/System.Xml.XDocument/ref/System.Xml.XDocument.cs +++ b/src/libraries/System.Xml.XDocument/ref/System.Xml.XDocument.cs @@ -358,7 +358,7 @@ internal XName() { } public string LocalName { get { throw null; } } public System.Xml.Linq.XNamespace Namespace { get { throw null; } } public string NamespaceName { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Xml.Linq.XName Get(string expandedName) { throw null; } public static System.Xml.Linq.XName Get(string localName, string namespaceName) { throw null; } public override int GetHashCode() { throw null; } @@ -378,7 +378,7 @@ internal XNamespace() { } public static System.Xml.Linq.XNamespace None { get { throw null; } } public static System.Xml.Linq.XNamespace Xml { get { throw null; } } public static System.Xml.Linq.XNamespace Xmlns { get { throw null; } } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public static System.Xml.Linq.XNamespace Get(string namespaceName) { throw null; } public override int GetHashCode() { throw null; } public System.Xml.Linq.XName GetName(string localName) { throw null; } diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs index 21d5661aaff40..67255c4f4b070 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Delegate.Mono.cs @@ -498,7 +498,7 @@ private static bool IsArgumentTypeMatchWithThis(Type delArgType, Type argType, b return _method.Invoke(target, args); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (!(obj is Delegate d) || !InternalEqualTypes(this, obj)) return false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs b/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs index a29e584f4d4ce..3b953d8648b6b 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/ModuleHandle.cs @@ -1,6 +1,7 @@ // 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; using System.Reflection; namespace System @@ -112,7 +113,7 @@ public RuntimeTypeHandle GetRuntimeTypeHandleFromMetadataToken(int typeToken) return ResolveTypeHandle(typeToken); } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null || GetType() != obj.GetType()) return false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs index d36552cd50708..a801b8772ca44 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -65,7 +65,7 @@ internal bool HasSingleTarget // Equals: two multicast delegates are equal if their base is equal // and their invocations list is equal. // - public sealed override bool Equals(object? obj) + public sealed override bool Equals([NotNullWhen(true)] object? obj) { if (!base.Equals(obj)) return false; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/ValueType.cs b/src/mono/netcore/System.Private.CoreLib/src/System/ValueType.cs index 52eb3106a02ca..8ce01bec0c7cf 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/ValueType.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/ValueType.cs @@ -1,6 +1,7 @@ // 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; using System.Runtime.CompilerServices; namespace System @@ -42,7 +43,7 @@ internal static bool DefaultEquals(object o1, object o2) return true; } - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { if (obj == null) return false;