diff --git a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs index 3c29ff3b84f04d..0f977d2b5368fc 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateOnly.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Globalization; +using System.Diagnostics.CodeAnalysis; namespace System { @@ -237,7 +238,7 @@ public int CompareTo(object? value) /// /// The object to compare to this instance. /// true if value is an instance of DateOnly and equals the value of this instance; otherwise, false. - public override bool Equals(object? value) => value is DateOnly dateOnly && _dayNumber == dateOnly._dayNumber; + public override bool Equals([NotNullWhen(true)] object? value) => value is DateOnly dateOnly && _dayNumber == dateOnly._dayNumber; /// /// Returns the hash code for this instance. diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Label.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Label.cs index a5c69737b9bcad..187933ea16f44d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Label.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Label.cs @@ -13,6 +13,8 @@ ** ===========================================================*/ +using System.Diagnostics.CodeAnalysis; + namespace System.Reflection.Emit { // The Label class is an opaque representation of a label used by the @@ -31,7 +33,7 @@ namespace System.Reflection.Emit public override int GetHashCode() => m_label; - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is Label other && Equals(other); public bool Equals(Label obj) => diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs index cb40f1af0ef49c..2a44ed9e76d646 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Threading; +using System.Diagnostics.CodeAnalysis; namespace System.Reflection.Emit { @@ -108,7 +109,7 @@ public string? Name } } - public override bool Equals(object? obj) => + public override bool Equals([NotNullWhen(true)] object? obj) => obj is OpCode other && Equals(other); public bool Equals(OpCode obj) => obj.Value == Value; diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Pointer.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Pointer.cs index ef8e82a9b0f18f..f6f09113c32219 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Pointer.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Pointer.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; namespace System.Reflection { @@ -39,7 +40,7 @@ public static object Box(void* ptr, Type type) return ((Pointer)ptr)._ptr; } - public override unsafe bool Equals(object? obj) + public override unsafe bool Equals([NotNullWhen(true)] object? obj) { if (obj is Pointer pointer) { diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs index 1ded5053f25339..74d08f67513c7e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Globalization; +using System.Diagnostics.CodeAnalysis; namespace System { @@ -307,7 +308,7 @@ public int CompareTo(object? value) /// /// The object to compare to this instance. /// true if value is an instance of TimeOnly and equals the value of this instance; otherwise, false. - public override bool Equals(object? value) => value is TimeOnly timeOnly && _ticks == timeOnly._ticks; + public override bool Equals([NotNullWhen(true)] object? value) => value is TimeOnly timeOnly && _ticks == timeOnly._ticks; /// /// Returns the hash code for this instance. diff --git a/src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs b/src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs index ef1ede20347e4d..449916fb2a442f 100644 --- a/src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs +++ b/src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs @@ -59,7 +59,7 @@ public virtual void UsingNamespace(string usingNamespace) { } public readonly partial struct Label : System.IEquatable { private readonly 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.Reflection.Emit.Label obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Reflection.Emit.Label a, System.Reflection.Emit.Label b) { throw null; } diff --git a/src/libraries/System.Reflection.Primitives/ref/System.Reflection.Primitives.cs b/src/libraries/System.Reflection.Primitives/ref/System.Reflection.Primitives.cs index 225eb1558951af..c14ab12ccdc2ed 100644 --- a/src/libraries/System.Reflection.Primitives/ref/System.Reflection.Primitives.cs +++ b/src/libraries/System.Reflection.Primitives/ref/System.Reflection.Primitives.cs @@ -30,7 +30,7 @@ public enum FlowControl public System.Reflection.Emit.StackBehaviour StackBehaviourPop { get { throw null; } } public System.Reflection.Emit.StackBehaviour StackBehaviourPush { get { throw null; } } public short 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 bool Equals(System.Reflection.Emit.OpCode obj) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Reflection.Emit.OpCode a, System.Reflection.Emit.OpCode b) { throw null; } diff --git a/src/libraries/System.Runtime/ref/System.Runtime.cs b/src/libraries/System.Runtime/ref/System.Runtime.cs index a78df2b946602a..005a751d646215 100644 --- a/src/libraries/System.Runtime/ref/System.Runtime.cs +++ b/src/libraries/System.Runtime/ref/System.Runtime.cs @@ -1328,7 +1328,7 @@ public static partial class Convert public int CompareTo(System.DateOnly value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.DateOnly value) { 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 System.DateOnly Parse(System.ReadOnlySpan s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; } public static System.DateOnly ParseExact(System.ReadOnlySpan s, System.ReadOnlySpan format, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; } @@ -3845,7 +3845,7 @@ public ThreadStaticAttribute() { } public int CompareTo(System.TimeOnly value) { throw null; } public int CompareTo(object? value) { throw null; } public bool Equals(System.TimeOnly value) { 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 System.TimeOnly Parse(System.ReadOnlySpan s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; } public static System.TimeOnly ParseExact(System.ReadOnlySpan s, System.ReadOnlySpan format, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; } @@ -8842,7 +8842,7 @@ internal Pointer() { } public unsafe static object Box(void* ptr, System.Type type) { throw null; } void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { } public unsafe static void* Unbox(object ptr) { 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]