dotnet_diagnostic.CA1065.severity = none
# CA1066: Implement IEquatable when overriding Object.Equals
-dotnet_diagnostic.CA1066.severity = none
+dotnet_diagnostic.CA1066.severity = warning
# CA1067: Override Object.Equals(object) when implementing IEquatable<T>
-dotnet_diagnostic.CA1067.severity = none
+dotnet_diagnostic.CA1067.severity = warning
# CA1068: CancellationToken parameters must come last
dotnet_diagnostic.CA1068.severity = none
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\StackFrame.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\StackFrameHelper.cs" />
<Compile Include="$(BclSourcesRoot)\System\Diagnostics\StackTrace.CoreCLR.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Diagnostics\SymbolStore\SymAddressKind.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Diagnostics\SymbolStore\Token.cs" />
<Compile Include="$(BclSourcesRoot)\System\Enum.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Environment.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Exception.CoreCLR.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-**
-**
-** Represents address Kinds used with local variables, parameters, and
-** fields.
-**
-**
-===========================================================*/
-// Only statics, does not need to be marked with the serializable attribute
-
-namespace System.Diagnostics.SymbolStore
-{
- internal enum SymAddressKind
- {
- // ILOffset: addr1 = IL local var or param index.
- ILOffset = 1,
-
- // NativeRVA: addr1 = RVA into module.
- NativeRVA = 2,
-
- // NativeRegister: addr1 = register the var is stored in.
- NativeRegister = 3,
-
- // NativeRegisterRelative: addr1 = register, addr2 = offset.
- NativeRegisterRelative = 4,
-
- // NativeOffset: addr1 = offset from start of parent.
- NativeOffset = 5,
-
- // NativeRegisterRegister: addr1 = reg low, addr2 = reg high.
- NativeRegisterRegister = 6,
-
- // NativeRegisterStack: addr1 = reg low, addr2 = reg stk, addr3 = offset.
- NativeRegisterStack = 7,
-
- // NativeStackRegister: addr1 = reg stk, addr2 = offset, addr3 = reg high.
- NativeStackRegister = 8,
-
- // BitField: addr1 = field start, addr = field length.
- BitField = 9,
-
- // NativeSectionOffset: addr1 = section, addr = offset
- NativeSectionOffset = 10,
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-/*============================================================
-**
-**
-** Small value class used by the SymbolStore package for passing
-** around metadata tokens.
-**
-===========================================================*/
-
-using System.Diagnostics.CodeAnalysis;
-
-namespace System.Diagnostics.SymbolStore
-{
- internal struct SymbolToken
- {
- internal int m_token;
-
- public SymbolToken(int val) { m_token = val; }
-
- public int GetToken() { return m_token; }
-
- public override int GetHashCode() { return m_token; }
-
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- if (obj is SymbolToken)
- return Equals((SymbolToken)obj);
- else
- return false;
- }
-
- public bool Equals(SymbolToken obj)
- {
- return obj.m_token == m_token;
- }
- }
-}
}
}
+#pragma warning disable CA1066 // IEquatable<MetadataImport> interface implementation isn't used
internal readonly struct MetadataImport
+#pragma warning restore CA1067
{
private readonly IntPtr m_metadataImport2;
private readonly object? m_keepalive;
}
}
- public unsafe partial struct ModuleHandle
+ public unsafe partial struct ModuleHandle : IEquatable<ModuleHandle>
{
#region Public Static Members
public static readonly ModuleHandle EmptyHandle;
namespace System
{
- public struct ModuleHandle
+ public struct ModuleHandle : IEquatable<ModuleHandle>
{
public static readonly ModuleHandle EmptyHandle;
// - The TypeUnifier extension class provides a more friendly interface to the rest of the codebase.
//
+#pragma warning disable CA1067 // override Equals because it implements IEquatable<T>
+
namespace System.Reflection.Runtime.General
{
internal static partial class TypeUnifier
using Internal.Reflection.Tracing;
+#pragma warning disable CA1067 // override Equals because it implements IEquatable<T>
+
namespace System.Reflection.Runtime.TypeInfos
{
//
WriteLine("#pragma warning disable 649");
WriteLine("#pragma warning disable 169");
WriteLine("#pragma warning disable 282 // There is no defined ordering between fields in multiple declarations of partial class or struct");
+ WriteLine("#pragma warning disable CA1066 // IEquatable<T> implementations aren't used");
WriteLine("#pragma warning disable IDE0059");
WriteLine();
#pragma warning disable 649
#pragma warning disable 169
#pragma warning disable 282 // There is no defined ordering between fields in multiple declarations of partial class or struct
+#pragma warning disable CA1066 // IEquatable<T> implementations aren't used
#pragma warning disable IDE0059
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-
#pragma warning disable 169
-
-// There is no defined ordering between fields in multiple declarations of partial class or struct
-#pragma warning disable 282
-
+#pragma warning disable 282 // There is no defined ordering between fields in multiple declarations of partial class or struct
+#pragma warning disable CA1066 // IEquatable<T> implementations aren't used
using System;
using System.IO;
/// type system do not have a known size. This type is used to make such sizes viral through the type layout
/// computations)
/// </summary>
+#pragma warning disable CA1066 // IEquatable<T> implementation wouldn't be used
public struct LayoutInt
+#pragma warning restore CA1066
{
private int _value;
// The .NET Foundation licenses this file to you under the MIT license.
using System;
-using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
-using System.Text;
internal static partial class Interop
{
private uint _isIPv6; // Non-zero if this is an IPv6 address; zero for IPv4.
internal uint ScopeId; // Scope ID (IPv6 only)
+ public override unsafe int GetHashCode()
+ {
+ HashCode h = default;
+ fixed (byte* ptr = Address)
+ {
+ h.AddBytes(new ReadOnlySpan<byte>(ptr, IsIPv6 ? IPv6AddressBytes : IPv4AddressBytes));
+ }
+ return h.ToHashCode();
+ }
+
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is IPAddress other && Equals(other);
+
public bool Equals(IPAddress other)
{
int addressByteCount;
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Diagnostics.CodeAnalysis;
namespace Microsoft.Extensions.DependencyInjection.ServiceLookup
{
Slot = slot;
}
- public bool Equals(ServiceCacheKey other)
- {
- return Type == other.Type && Slot == other.Slot;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(ServiceCacheKey other) =>
+ Type == other.Type && Slot == other.Slot;
+
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is ServiceCacheKey other && Equals(other);
public override int GetHashCode()
{
namespace Microsoft.Extensions.Logging
{
- public readonly partial struct EventId
+ public readonly partial struct EventId : System.IEquatable<Microsoft.Extensions.Logging.EventId>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
// 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.Diagnostics.CodeAnalysis;
namespace Microsoft.Extensions.Logging
/// <summary>
/// Identifies a logging event. The primary identifier is the "Id" property, with the "Name" property providing a short description of this type of event.
/// </summary>
- public readonly struct EventId
+ public readonly struct EventId : IEquatable<EventId>
{
/// <summary>
/// Implicitly creates an EventId from the given <see cref="int"/>.
/// <summary>
/// Contains all the key/values in the collection that hash to the same value.
/// </summary>
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
internal readonly struct HashBucket : IEnumerable<KeyValuePair<TKey, TValue>>
+#pragma warning restore CA1066
{
/// <summary>
/// One of the values in this bucket.
/// <summary>
/// Contains all the keys in the collection that hash to the same value.
/// </summary>
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
internal readonly struct HashBucket
+#pragma warning restore CA1066
{
/// <summary>
/// One of the values in this bucket.
namespace System.Collections.Specialized
{
- public partial struct BitVector32
+ public partial struct BitVector32 : System.IEquatable<System.Collections.Specialized.BitVector32>
{
private int _dummyPrimitive;
public BitVector32(System.Collections.Specialized.BitVector32 value) { throw null; }
public static int CreateMask(int previous) { throw null; }
public static System.Collections.Specialized.BitVector32.Section CreateSection(short maxValue) { throw null; }
public static System.Collections.Specialized.BitVector32.Section CreateSection(short maxValue, System.Collections.Specialized.BitVector32.Section previous) { throw null; }
+ public bool Equals(System.Collections.Specialized.BitVector32 other) { 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; }
public static string ToString(System.Collections.Specialized.BitVector32 value) { throw null; }
- public readonly partial struct Section
+ public readonly partial struct Section : System.IEquatable<System.Collections.Specialized.BitVector32.Section>
{
private readonly int _dummyPrimitive;
public short Mask { get { throw null; } }
/// <para>Provides a simple light bit vector with easy integer or Boolean access to
/// a 32 bit storage.</para>
/// </devdoc>
- public struct BitVector32
+ public struct BitVector32 : IEquatable<BitVector32>
{
private uint _data;
return new Section(mask, offset);
}
- public override bool Equals([NotNullWhen(true)] object? o) => o is BitVector32 other && _data == other._data;
+ public override bool Equals([NotNullWhen(true)] object? o) => o is BitVector32 other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(BitVector32 other) => _data == other._data;
public override int GetHashCode() => _data.GetHashCode();
/// <para>
/// Represents an section of the vector that can contain a integer number.</para>
/// </devdoc>
- public readonly struct Section
+ public readonly struct Section : IEquatable<Section>
{
private readonly short _mask;
private readonly short _offset;
Assert.True(new BitVector32(0).Equals(original));
Assert.True(original.Equals(new BitVector32(0)));
+ Assert.True(original.Equals((object)original));
+ Assert.True(new BitVector32().Equals((object)original));
+ Assert.True(original.Equals((object)new BitVector32()));
+ Assert.True(new BitVector32(0).Equals((object)original));
+ Assert.True(original.Equals((object)new BitVector32(0)));
+
BitVector32 other = new BitVector32(int.MaxValue / 2 - 1);
Assert.True(other.Equals(other));
Assert.True(new BitVector32(int.MaxValue / 2 - 1).Equals(other));
Assert.True(other.Equals(new BitVector32(int.MaxValue / 2 - 1)));
+ Assert.True(other.Equals((object)other));
+ Assert.True(new BitVector32(int.MaxValue / 2 - 1).Equals((object)other));
+ Assert.True(other.Equals((object)new BitVector32(int.MaxValue / 2 - 1)));
+
Assert.False(other.Equals(original));
Assert.False(original.Equals(other));
Assert.False(other.Equals(null));
Assert.False(original.Equals(null));
Assert.False(other.Equals(int.MaxValue / 2 - 1));
Assert.False(original.Equals(0));
+
+ Assert.False(other.Equals((object)original));
+ Assert.False(original.Equals((object)other));
+ Assert.False(other.Equals(int.MaxValue / 2 - 1));
+ Assert.False(original.Equals(0));
}
[Fact]
}
namespace System.ComponentModel.Composition.ReflectionModel
{
- public partial struct LazyMemberInfo
+ public partial struct LazyMemberInfo : System.IEquatable<System.ComponentModel.Composition.ReflectionModel.LazyMemberInfo>
{
private object _dummy;
private int _dummyPrimitive;
public LazyMemberInfo(System.Reflection.MemberTypes memberType, System.Func<System.Reflection.MemberInfo[]> accessorsCreator) { throw null; }
public LazyMemberInfo(System.Reflection.MemberTypes memberType, params System.Reflection.MemberInfo[] accessors) { throw null; }
public System.Reflection.MemberTypes MemberType { get { throw null; } }
+ public bool Equals(System.ComponentModel.Composition.ReflectionModel.LazyMemberInfo other) { throw null; }
public override bool Equals(object? obj) { throw null; }
public System.Reflection.MemberInfo[] GetAccessors() { throw null; }
public override int GetHashCode() { throw null; }
namespace System.ComponentModel.Composition.ReflectionModel
{
- public struct LazyMemberInfo
+ public struct LazyMemberInfo : IEquatable<LazyMemberInfo>
{
private readonly MemberTypes _memberType;
private MemberInfo?[]? _accessors;
throw new Exception(SR.Diagnostic_InternalExceptionMessage);
}
- public override bool Equals(object? obj)
- {
- if (obj is not LazyMemberInfo that)
- {
- return false;
- }
+ public override bool Equals(object? obj) =>
+ obj is LazyMemberInfo other && Equals(other);
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(LazyMemberInfo other)
+ {
// Different member types mean different members
- if (_memberType != that._memberType)
+ if (_memberType != other._memberType)
{
return false;
}
// if any of the lazy memebers create accessors in a delay-loaded fashion, we simply compare the creators
- if ((_accessorsCreator != null) || (that._accessorsCreator != null))
+ if ((_accessorsCreator != null) || (other._accessorsCreator != null))
{
- return object.Equals(_accessorsCreator, that._accessorsCreator);
+ return object.Equals(_accessorsCreator, other._accessorsCreator);
}
// we are dealing with explicitly passed accessors in both cases
- if (_accessors == null || that._accessors == null)
+ if (_accessors == null || other._accessors == null)
{
throw new Exception(SR.Diagnostic_InternalExceptionMessage);
}
- return _accessors.SequenceEqual(that._accessors);
+ return _accessors.SequenceEqual(other._accessors);
}
public static bool operator ==(LazyMemberInfo left, LazyMemberInfo right)
public object? Invoke() { throw null; }
}
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
- public readonly partial struct MemberRelationship
+ public readonly partial struct MemberRelationship : System.IEquatable<System.ComponentModel.Design.Serialization.MemberRelationship>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public bool IsEmpty { get { throw null; } }
public System.ComponentModel.MemberDescriptor Member { get { throw null; } }
public object? Owner { get { throw null; } }
+ public bool Equals(System.ComponentModel.Design.Serialization.MemberRelationship other) { 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.ComponentModel.Design.Serialization.MemberRelationship left, System.ComponentModel.Design.Serialization.MemberRelationship right) { throw null; }
/// <summary>
/// Used as storage in our relationship table
/// </summary>
- private struct RelationshipEntry
+ private struct RelationshipEntry : IEquatable<RelationshipEntry>
{
internal WeakReference _owner;
internal MemberDescriptor _member;
public override bool Equals([NotNullWhen(true)] object? o)
{
Debug.Assert(o is RelationshipEntry, "This is only called indirectly from a dictionary only containing RelationshipEntry structs.");
- return this == (RelationshipEntry)o;
+ return Equals((RelationshipEntry)o);
}
- public static bool operator ==(RelationshipEntry re1, RelationshipEntry re2)
+ public bool Equals(RelationshipEntry other)
{
- object? owner1 = (re1._owner.IsAlive ? re1._owner.Target : null);
- object? owner2 = (re2._owner.IsAlive ? re2._owner.Target : null);
- return owner1 == owner2 && re1._member.Equals(re2._member);
+ object? owner1 = (_owner.IsAlive ? _owner.Target : null);
+ object? owner2 = (other._owner.IsAlive ? other._owner.Target : null);
+ return owner1 == owner2 && _member.Equals(other._member);
}
- public static bool operator !=(RelationshipEntry re1, RelationshipEntry re2)
- {
- return !(re1 == re2);
- }
+ public static bool operator ==(RelationshipEntry re1, RelationshipEntry re2) => re1.Equals(re2);
+
+ public static bool operator !=(RelationshipEntry re1, RelationshipEntry re2) => !re1.Equals(re2);
public override int GetHashCode() => _hashCode;
}
/// <summary>
/// This class represents a single relationship between an object and a member.
/// </summary>
- public readonly struct MemberRelationship
+ public readonly struct MemberRelationship : IEquatable<MemberRelationship>
{
public static readonly MemberRelationship Empty;
/// <summary>
/// Infrastructure support to make this a first class struct
/// </summary>
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- return obj is MemberRelationship rel && rel.Owner == Owner && rel.Member == Member;
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is MemberRelationship rel && Equals(rel);
/// <summary>
/// Infrastructure support to make this a first class struct
/// </summary>
- public override int GetHashCode()
- {
- if (Owner == null)
- {
- return base.GetHashCode();
- }
+ public bool Equals(MemberRelationship other) => other.Owner == Owner && other.Member == Member;
- return Owner.GetHashCode() ^ Member.GetHashCode();
- }
/// <summary>
/// Infrastructure support to make this a first class struct
/// </summary>
- public static bool operator ==(MemberRelationship left, MemberRelationship right)
- {
- return left.Owner == right.Owner && left.Member == right.Member;
- }
+ public override int GetHashCode() => Owner is null ? base.GetHashCode() : Owner.GetHashCode() ^ Member.GetHashCode();
/// <summary>
/// Infrastructure support to make this a first class struct
/// </summary>
- public static bool operator !=(MemberRelationship left, MemberRelationship right)
- {
- return !(left == right);
- }
+ public static bool operator ==(MemberRelationship left, MemberRelationship right) => left.Equals(right);
+
+ /// <summary>
+ /// Infrastructure support to make this a first class struct
+ /// </summary>
+ public static bool operator !=(MemberRelationship left, MemberRelationship right) => !left.Equals(right);
}
}
/// Provides a subset of the <see cref="System.Collections.Specialized.BitVector32"/> surface area, using volatile
/// operations for reads and interlocked operations for writes.
/// </summary>
- internal struct InterlockedBitVector32
+ internal struct InterlockedBitVector32 : IEquatable<InterlockedBitVector32>
{
private int _data;
return previous == 0 ? 1 : previous << 1;
}
- public override bool Equals([NotNullWhen(true)] object? o) => o is InterlockedBitVector32 vector && _data == vector._data;
+ public override bool Equals([NotNullWhen(true)] object? o) => o is InterlockedBitVector32 other && Equals(other);
+
+ public bool Equals(InterlockedBitVector32 other) => _data == other._data;
public override int GetHashCode() => base.GetHashCode();
}
public SqlAlreadyFilledException(string? message, System.Exception? e) { }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlBinary : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlBinary : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlBinary>
{
private object _dummy;
private int _dummyPrimitive;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlBinary Concat(System.Data.SqlTypes.SqlBinary x, System.Data.SqlTypes.SqlBinary y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlBinary x, System.Data.SqlTypes.SqlBinary y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlBinary other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public override string ToString() { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlBoolean : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlBoolean : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlBoolean>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlBoolean False;
public int CompareTo(System.Data.SqlTypes.SqlBoolean value) { throw null; }
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlBoolean x, System.Data.SqlTypes.SqlBoolean y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlBoolean other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Xor(System.Data.SqlTypes.SqlBoolean x, System.Data.SqlTypes.SqlBoolean y) { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlByte : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlByte : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlByte>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlByte MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlByte Divide(System.Data.SqlTypes.SqlByte x, System.Data.SqlTypes.SqlByte y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlByte x, System.Data.SqlTypes.SqlByte y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlByte other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
BinarySort = 32768,
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlDateTime : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlDateTime : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlDateTime>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlDateTime MaxValue;
public int CompareTo(System.Data.SqlTypes.SqlDateTime value) { throw null; }
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlDateTime x, System.Data.SqlTypes.SqlDateTime y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlDateTime other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public override string ToString() { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlDecimal : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlDecimal : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlDecimal>
{
private int _dummyPrimitive;
public static readonly byte MaxPrecision;
public static System.Data.SqlTypes.SqlDecimal ConvertToPrecScale(System.Data.SqlTypes.SqlDecimal n, int precision, int scale) { throw null; }
public static System.Data.SqlTypes.SqlDecimal Divide(System.Data.SqlTypes.SqlDecimal x, System.Data.SqlTypes.SqlDecimal y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlDecimal x, System.Data.SqlTypes.SqlDecimal y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlDecimal other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public static System.Data.SqlTypes.SqlDecimal Floor(System.Data.SqlTypes.SqlDecimal n) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Data.SqlTypes.SqlDecimal Truncate(System.Data.SqlTypes.SqlDecimal n, int position) { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlDouble : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlDouble : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlDouble>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlDouble MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlDouble Divide(System.Data.SqlTypes.SqlDouble x, System.Data.SqlTypes.SqlDouble y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlDouble x, System.Data.SqlTypes.SqlDouble y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlDouble other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public override string ToString() { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlGuid : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlGuid : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlGuid>
{
private object _dummy;
private int _dummyPrimitive;
public int CompareTo(System.Data.SqlTypes.SqlGuid value) { throw null; }
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlGuid x, System.Data.SqlTypes.SqlGuid y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlGuid other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public override string ToString() { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlInt16 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlInt16 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlInt16>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlInt16 MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlInt16 Divide(System.Data.SqlTypes.SqlInt16 x, System.Data.SqlTypes.SqlInt16 y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlInt16 x, System.Data.SqlTypes.SqlInt16 y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlInt16 other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public static System.Data.SqlTypes.SqlInt16 Xor(System.Data.SqlTypes.SqlInt16 x, System.Data.SqlTypes.SqlInt16 y) { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlInt32 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlInt32 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlInt32>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlInt32 MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlInt32 Divide(System.Data.SqlTypes.SqlInt32 x, System.Data.SqlTypes.SqlInt32 y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlInt32 x, System.Data.SqlTypes.SqlInt32 y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlInt32 other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public static System.Data.SqlTypes.SqlInt32 Xor(System.Data.SqlTypes.SqlInt32 x, System.Data.SqlTypes.SqlInt32 y) { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlInt64 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlInt64 : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlInt64>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlInt64 MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlInt64 Divide(System.Data.SqlTypes.SqlInt64 x, System.Data.SqlTypes.SqlInt64 y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlInt64 x, System.Data.SqlTypes.SqlInt64 y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlInt64 other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public static System.Data.SqlTypes.SqlInt64 Xor(System.Data.SqlTypes.SqlInt64 x, System.Data.SqlTypes.SqlInt64 y) { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlMoney : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlMoney : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlMoney>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlMoney MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlMoney Divide(System.Data.SqlTypes.SqlMoney x, System.Data.SqlTypes.SqlMoney y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlMoney x, System.Data.SqlTypes.SqlMoney y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlMoney other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public SqlNullValueException(string? message, System.Exception? e) { }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlSingle : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlSingle : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlSingle>
{
private int _dummyPrimitive;
public static readonly System.Data.SqlTypes.SqlSingle MaxValue;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlSingle Divide(System.Data.SqlTypes.SqlSingle x, System.Data.SqlTypes.SqlSingle y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlSingle x, System.Data.SqlTypes.SqlSingle y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlSingle other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.Xml.XmlQualifiedName GetXsdType(System.Xml.Schema.XmlSchemaSet schemaSet) { throw null; }
public override string ToString() { throw null; }
}
[System.Xml.Serialization.XmlSchemaProviderAttribute("GetXsdType")]
- public partial struct SqlString : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable
+ public partial struct SqlString : System.Data.SqlTypes.INullable, System.IComparable, System.Xml.Serialization.IXmlSerializable, System.IEquatable<System.Data.SqlTypes.SqlString>
{
private object _dummy;
private int _dummyPrimitive;
public int CompareTo(object? value) { throw null; }
public static System.Data.SqlTypes.SqlString Concat(System.Data.SqlTypes.SqlString x, System.Data.SqlTypes.SqlString y) { throw null; }
public static System.Data.SqlTypes.SqlBoolean Equals(System.Data.SqlTypes.SqlString x, System.Data.SqlTypes.SqlString y) { throw null; }
+ public bool Equals(System.Data.SqlTypes.SqlString other) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public byte[]? GetNonUnicodeBytes() { throw null; }
namespace System.Data
{
- internal readonly struct DataKey
+ internal readonly struct DataKey : IEquatable<DataKey>
{
private const int maxColumns = 32;
return Equals((DataKey)value);
}
- internal bool Equals(DataKey value)
+ public bool Equals(DataKey value)
{
//check to see if this.columns && key2's columns are equal...
DataColumn[] column1 = _columns;
namespace System.Data.SqlTypes
{
[XmlSchemaProvider("GetXsdType")]
- public struct SqlBinary : INullable, IComparable, IXmlSerializable
+ public struct SqlBinary : INullable, IComparable, IXmlSerializable, IEquatable<SqlBinary>
{
// NOTE: If any instance fields change, update SqlTypeWorkarounds type in System.Data.SqlClient.
private byte[]? _value;
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlBinary))
- {
- return false;
- }
-
- SqlBinary i = (SqlBinary)value;
-
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlBinary other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlBinary other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// Hash a byte array.
// Trailing zeroes/spaces would affect the hash value, so caller needs to
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlBoolean : INullable, IComparable, IXmlSerializable
+ public struct SqlBoolean : INullable, IComparable, IXmlSerializable, IEquatable<SqlBoolean>
{
// m_value: 2 (true), 1 (false), 0 (unknown/Null)
private byte m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlBoolean))
- {
- return false;
- }
-
- SqlBoolean i = (SqlBoolean)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlBoolean other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlBoolean other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlByte : INullable, IComparable, IXmlSerializable
+ public struct SqlByte : INullable, IComparable, IXmlSerializable, IEquatable<SqlByte>
{
private bool m_fNotNull; // false if null. Do not rename (binary serialization)
private byte m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlByte))
- {
- return false;
- }
-
- SqlByte i = (SqlByte)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlByte other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlByte other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlDateTime : INullable, IComparable, IXmlSerializable
+ public struct SqlDateTime : INullable, IComparable, IXmlSerializable, IEquatable<SqlDateTime>
{
private bool m_fNotNull; // false if null. Do not rename (binary serialization)
private int m_day; // Day from 1900/1/1, could be negative. Range: Jan 1 1753 - Dec 31 9999. Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlDateTime))
- {
- return false;
- }
-
- SqlDateTime i = (SqlDateTime)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlDateTime other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlDateTime other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
/// </summary>
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
- public struct SqlDecimal : INullable, IComparable, IXmlSerializable
+ public struct SqlDecimal : INullable, IComparable, IXmlSerializable, IEquatable<SqlDecimal>
{
// data in CSsNumeric in SQL Server
// BYTE m_cbLen; // # of DWORDs + 1 (1 is for sign)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlDecimal))
- {
- return false;
- }
-
- SqlDecimal i = (SqlDecimal)value;
-
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlDecimal other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlDecimal other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
public override int GetHashCode()
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlDouble : INullable, IComparable, IXmlSerializable
+ public struct SqlDouble : INullable, IComparable, IXmlSerializable, IEquatable<SqlDouble>
{
private bool m_fNotNull; // false if null. Do not rename (binary serialization)
private double m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlDouble))
- {
- return false;
- }
-
- SqlDouble i = (SqlDouble)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlDouble other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlDouble other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[Serializable]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlGuid : INullable, IComparable, IXmlSerializable
+ public struct SqlGuid : INullable, IComparable, IXmlSerializable, IEquatable<SqlGuid>
{
private const int SizeOfGuid = 16;
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlGuid))
- {
- return false;
- }
-
- SqlGuid i = (SqlGuid)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlGuid other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlGuid other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlInt16 : INullable, IComparable, IXmlSerializable
+ public struct SqlInt16 : INullable, IComparable, IXmlSerializable, IEquatable<SqlInt16>
{
private bool m_fNotNull; // false if null. Do not rename (binary serialization)
private short m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlInt16))
- {
- return false;
- }
-
- SqlInt16 i = (SqlInt16)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlInt16 other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlInt16 other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlInt32 : INullable, IComparable, IXmlSerializable
+ public struct SqlInt32 : INullable, IComparable, IXmlSerializable, IEquatable<SqlInt32>
{
private bool m_fNotNull; // false if null, the default ctor (plain 0) will make it Null. Do not rename (binary serialization)
private int m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlInt32))
- {
- return false;
- }
-
- SqlInt32 i = (SqlInt32)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlInt32 other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlInt32 other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlInt64 : INullable, IComparable, IXmlSerializable
+ public struct SqlInt64 : INullable, IComparable, IXmlSerializable, IEquatable<SqlInt64>
{
private bool m_fNotNull; // false if null. Do not rename (binary serialization)
private long m_value; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlInt64))
- {
- return false;
- }
-
- SqlInt64 i = (SqlInt64)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlInt64 other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlInt64 other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
/// </summary>
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
- public struct SqlMoney : INullable, IComparable, IXmlSerializable
+ public struct SqlMoney : INullable, IComparable, IXmlSerializable, IEquatable<SqlMoney>
{
// NOTE: If any instance fields change, update SqlTypeWorkarounds type in System.Data.SqlClient.
private bool _fNotNull; // false if null
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlMoney))
- {
- return false;
- }
-
- SqlMoney i = (SqlMoney)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlMoney other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlMoney other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
+ public override int GetHashCode() =>
// Don't use Value property, because Value will convert to Decimal, which is not necessary.
- return IsNull ? 0 : _value.GetHashCode();
- }
+ IsNull ? 0 : _value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
/// </summary>
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
- public struct SqlSingle : INullable, IComparable, IXmlSerializable
+ public struct SqlSingle : INullable, IComparable, IXmlSerializable, IEquatable<SqlSingle>
{
private bool _fNotNull; // false if null
private float _value;
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlSingle))
- {
- return false;
- }
-
- SqlSingle i = (SqlSingle)value;
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlSingle other && Equals(other);
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlSingle other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
- public override int GetHashCode()
- {
- return IsNull ? 0 : Value.GetHashCode();
- }
+ public override int GetHashCode() => IsNull ? 0 : Value.GetHashCode();
XmlSchema? IXmlSerializable.GetSchema() { return null; }
[StructLayout(LayoutKind.Sequential)]
[XmlSchemaProvider("GetXsdType")]
[System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
- public struct SqlString : INullable, IComparable, IXmlSerializable
+ public struct SqlString : INullable, IComparable, IXmlSerializable, IEquatable<SqlString>
{
private string? m_value; // Do not rename (binary serialization)
private CompareInfo? m_cmpInfo; // Do not rename (binary serialization)
}
// Compares this instance with a specified object
- public override bool Equals([NotNullWhen(true)] object? value)
- {
- if (!(value is SqlString))
- {
- return false;
- }
-
- SqlString i = (SqlString)value;
-
- if (i.IsNull || IsNull)
- return (i.IsNull && IsNull);
- else
- return (this == i).Value;
- }
+ public override bool Equals([NotNullWhen(true)] object? value) =>
+ value is SqlString other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(SqlString other) =>
+ other.IsNull || IsNull ? other.IsNull && IsNull :
+ (this == other).Value;
// For hashing purpose
public override int GetHashCode()
namespace System.Data
{
- internal readonly struct IndexField
+ internal readonly struct IndexField : IEquatable<IndexField>
{
public readonly DataColumn Column;
public readonly bool IsDescending; // false = Asc; true = Desc what is default value for this?
IsDescending = isDescending;
}
- public static bool operator ==(IndexField if1, IndexField if2) =>
- if1.Column == if2.Column && if1.IsDescending == if2.IsDescending;
+ public static bool operator ==(IndexField if1, IndexField if2) => if1.Equals(if2);
- public static bool operator !=(IndexField if1, IndexField if2) => !(if1 == if2);
+ public static bool operator !=(IndexField if1, IndexField if2) => !if1.Equals(if2);
// must override Equals if == operator is defined
- public override bool Equals([NotNullWhen(true)] object? obj) => obj is IndexField ?
- this == (IndexField)obj :
- false;
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is IndexField other && Equals(other);
+
+ public bool Equals(IndexField other) => Column == other.Column && IsDescending == other.IsDescending;
// must override GetHashCode if Equals is redefined
public override int GetHashCode() =>
// Equals
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.False(_test3.Equals(_test2));
+ Assert.False(_test3.Equals((object)_test2));
Assert.True(_test3.Equals(_test1));
+ Assert.True(_test3.Equals((object)_test1));
// NotEquals
Assert.True(SqlBinary.NotEquals(_test1, _test2).Value);
SqlBoolean sqlFalse2 = new SqlBoolean(false);
Assert.True(_sqlTrue.Equals(sqlTrue2));
+ Assert.True(_sqlTrue.Equals((object)sqlTrue2));
Assert.True(_sqlFalse.Equals(sqlFalse2));
+ Assert.True(_sqlFalse.Equals((object)sqlFalse2));
Assert.False(_sqlTrue.Equals(_sqlFalse));
+ Assert.False(_sqlTrue.Equals((object)_sqlFalse));
Assert.False(_sqlFalse.Equals(_sqlTrue));
+ Assert.False(_sqlFalse.Equals((object)_sqlTrue));
Assert.False(_sqlTrue.Equals(SqlBoolean.Null));
Assert.False(_sqlFalse.Equals(SqlBoolean.Null));
SqlByte testByte180II = new SqlByte(180);
Assert.False(testByte0.Equals(testByte158));
+ Assert.False(testByte0.Equals((object)testByte158));
Assert.False(testByte158.Equals(testByte180));
+ Assert.False(testByte158.Equals((object)testByte180));
Assert.False(testByte180.Equals(new SqlString("TEST")));
Assert.True(testByte180.Equals(testByte180II));
+ Assert.True(testByte180.Equals((object)testByte180II));
}
[Fact]
public void EqualsMethods()
{
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.False(_test2.Equals(new SqlString("TEST")));
Assert.True(_test2.Equals(_test3));
+ Assert.True(_test2.Equals((object)_test3));
// Static Equals()-method
Assert.True(SqlDateTime.Equals(_test2, _test3).Value);
public void EqualsMethods()
{
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.False(_test2.Equals(new SqlString("TEST")));
Assert.True(_test2.Equals(_test3));
+ Assert.True(_test2.Equals((object)_test3));
// Static Equals()-method
Assert.True(SqlDecimal.Equals(_test2, _test2).Value);
SqlDouble test22 = new SqlDouble(1.8e180);
Assert.False(test0.Equals(test1));
+ Assert.False(test0.Equals((object)test1));
Assert.False(test1.Equals(test2));
+ Assert.False(test1.Equals((object)test2));
Assert.False(test2.Equals(new SqlString("TEST")));
Assert.True(test2.Equals(test22));
+ Assert.True(test2.Equals((object)test22));
// Static Equals()-method
Assert.True(SqlDouble.Equals(test2, test22).Value);
public void EqualsMethods()
{
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.False(_test2.Equals(_test4));
+ Assert.False(_test2.Equals((object)_test4));
Assert.False(_test2.Equals(new SqlString("TEST")));
Assert.True(_test2.Equals(_test3));
+ Assert.True(_test2.Equals((object)_test3));
// Static Equals()-method
Assert.True(SqlGuid.Equals(_test2, _test3).Value);
SqlInt16 test180II = new SqlInt16(180);
Assert.False(test0.Equals(test158));
+ Assert.False(test0.Equals((object)test158));
Assert.False(test158.Equals(test180));
+ Assert.False(test158.Equals((object)test180));
Assert.False(test180.Equals(new SqlString("TEST")));
Assert.True(test180.Equals(test180II));
+ Assert.True(test180.Equals((object)test180II));
}
[Fact]
SqlInt64 test180II = new SqlInt64(180);
Assert.False(test0.Equals(test158));
+ Assert.False(test0.Equals((object)test158));
Assert.False(test158.Equals(test180));
+ Assert.False(test158.Equals((object)test180));
Assert.False(test180.Equals(new SqlString("TEST")));
Assert.True(test180.Equals(test180II));
+ Assert.True(test180.Equals((object)test180II));
}
[Fact]
public void EqualsMethods()
{
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.True(_test2.Equals(_test3));
+ Assert.True(_test2.Equals((object)_test3));
Assert.False(SqlMoney.Equals(_test1, _test2).Value);
Assert.True(SqlMoney.Equals(_test3, _test2).Value);
}
SqlSingle test22 = new SqlSingle(1.8e32);
Assert.False(test0.Equals(test1));
+ Assert.False(test0.Equals((object)test1));
Assert.False(test1.Equals(test2));
+ Assert.False(test1.Equals((object)test2));
Assert.False(test2.Equals(new SqlString("TEST")));
Assert.True(test2.Equals(test22));
+ Assert.True(test2.Equals((object)test22));
// Static Equals()-method
Assert.True(SqlSingle.Equals(test2, test22).Value);
public void EqualsMethods()
{
Assert.False(_test1.Equals(_test2));
+ Assert.False(_test1.Equals((object)_test2));
Assert.False(_test3.Equals(_test1));
+ Assert.False(_test3.Equals((object)_test1));
Assert.False(_test2.Equals(new SqlString("TEST")));
Assert.True(_test2.Equals(_test3));
+ Assert.True(_test2.Equals((object)_test3));
// Static Equals()-method
Assert.True(SqlString.Equals(_test2, _test3).Value);
<ItemGroup>
<Compile Include="System.Diagnostics.PerformanceCounter.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'" />
<Compile Include="System.Diagnostics.PerformanceCounter.netframework.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
+ <Compile Include="System.Diagnostics.PerformanceCounter.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections.NonGeneric\ref\System.Collections.NonGeneric.csproj" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.InteropServices" />
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// ------------------------------------------------------------------------------
+// Changes to this file must follow the https://aka.ms/api-review process.
+// ------------------------------------------------------------------------------
+
+namespace System.Diagnostics
+{
+ public readonly partial struct CounterSample : System.IEquatable<System.Diagnostics.CounterSample>
+ {
+ }
+}
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<NoWarn>$(NoWarn);CA1847</NoWarn>
+ <NoWarn Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">$(NoWarn);CA1066</NoWarn>
<Nullable>annotations</Nullable>
<IsPackable>true</IsPackable>
<PackageDescription>Provides the System.Diagnostics.PerformanceCounter class, which allows access to Windows performance counters.
/// <summary>
/// A struct holding the raw data for a performance counter.
/// </summary>
- public readonly struct CounterSample
+ public readonly struct CounterSample : IEquatable<CounterSample>
{
private readonly long _rawValue;
private readonly long _baseValue;
BitField = 9,
NativeSectionOffset = 10,
}
- public readonly partial struct SymbolToken
+ public readonly partial struct SymbolToken : System.IEquatable<System.Diagnostics.SymbolStore.SymbolToken>
{
private readonly int _dummyPrimitive;
public SymbolToken(int val) { throw null; }
namespace System.Diagnostics.SymbolStore
{
- public readonly struct SymbolToken
+ public readonly struct SymbolToken : IEquatable<SymbolToken>
{
private readonly int _token;
namespace System.Drawing
{
+ public partial struct CharacterRange : System.IEquatable<System.Drawing.CharacterRange>
+ {
+ public bool Equals(System.Drawing.CharacterRange other) { throw null; }
+ }
public sealed partial class Graphics
{
public void DrawRectangle(System.Drawing.Pen pen, System.Drawing.RectangleF rect) { }
namespace System.Drawing
{
[StructLayout(LayoutKind.Sequential)]
- public struct CharacterRange
+ public struct CharacterRange : IEquatable<CharacterRange>
{
private int _first;
private int _length;
- /// <summary>
- /// Initializes a new instance of the <see cref='CharacterRange'/> class with the specified coordinates.
- /// </summary>
+ /// <summary>Initializes a new instance of the <see cref='CharacterRange'/> class with the specified coordinates.</summary>
public CharacterRange(int First, int Length)
{
_first = First;
_length = Length;
}
- /// <summary>
- /// Gets the First character position of this <see cref='CharacterRange'/>.
- /// </summary>
+ /// <summary>Gets the First character position of this <see cref='CharacterRange'/>.</summary>
public int First
{
get => _first;
set => _first = value;
}
- /// <summary>
- /// Gets the Length of this <see cref='CharacterRange'/>.
- /// </summary>
+ /// <summary>Gets the Length of this <see cref='CharacterRange'/>.</summary>
public int Length
{
get => _length;
set => _length = value;
}
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- if (!(obj is CharacterRange cr))
- {
- return false;
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is CharacterRange other && Equals(other);
- return First == cr.First && Length == cr.Length;
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(CharacterRange other) => First == other.First && Length == other.Length;
public static bool operator ==(CharacterRange cr1, CharacterRange cr2) => cr1.Equals(cr2);
- public static bool operator !=(CharacterRange cr1, CharacterRange cr2) => !(cr1 == cr2);
+ public static bool operator !=(CharacterRange cr1, CharacterRange cr2) => !cr1.Equals(cr2);
public override int GetHashCode() => HashCode.Combine(First, Length);
}
// 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;
+
namespace System.Drawing.Printing
{
- internal readonly partial struct TriState
+ internal readonly partial struct TriState : IEquatable<TriState>
{
private readonly byte _value; // 0 is "default", not false
public static readonly TriState False = new TriState(1);
public static readonly TriState True = new TriState(2);
- private TriState(byte value)
- {
- _value = value;
- }
+ private TriState(byte value) => _value = value;
- public bool IsDefault
- {
- get { return this == Default; }
- }
+ public bool IsDefault => this == Default;
- public bool IsFalse
- {
- get { return this == False; }
- }
+ public bool IsFalse => this == False;
- public bool IsNotDefault
- {
- get { return this != Default; }
- }
+ public bool IsNotDefault => this != Default;
- public bool IsTrue
- {
- get { return this == True; }
- }
+ public bool IsTrue => this == True;
- public static bool operator ==(TriState left, TriState right)
- {
- return left._value == right._value;
- }
+ public static bool operator ==(TriState left, TriState right) => left.Equals(right);
- public static bool operator !=(TriState left, TriState right)
- {
- return !(left == right);
- }
+ public static bool operator !=(TriState left, TriState right) => !left.Equals(right);
- public override bool Equals(object? o)
+ public override bool Equals([NotNullWhen(true)] object? o)
{
- TriState state = (TriState)o!;
- return _value == state._value;
+ Debug.Assert(o is TriState);
+ return Equals((TriState)o);
}
- public override int GetHashCode()
- {
- return _value;
- }
+ public bool Equals(TriState other) => _value == other._value;
- public static implicit operator TriState(bool value)
- {
- return (value) ? True : False;
- }
+ public override int GetHashCode() => _value;
+
+ public static implicit operator TriState(bool value) => value ? True : False;
public static explicit operator bool(TriState value)
{
if (value.IsDefault)
+ {
throw new InvalidCastException(SR.TriStateCompareError);
- else
- return (value == TriState.True);
- }
+ }
- /// <summary>
- /// Provides some interesting information about the TriState in String form.
- /// </summary>
- public override string ToString()
- {
- if (this == Default) return "Default";
- else if (this == False) return "False";
- else return "True";
+ return (value == TriState.True);
}
+
+ /// <summary>Provides some interesting information about the TriState in String form.</summary>
+ public override string ToString() =>
+ this == Default ? "Default" :
+ this == False ? "False" :
+ "True";
}
}
Assert.Equal(expected, range.Equals(obj));
if (obj is CharacterRange otherRange)
{
+ Assert.Equal(expected, range.Equals(otherRange));
Assert.Equal(expected, range == otherRange);
Assert.Equal(!expected, range != otherRange);
Assert.Equal(expected, range.GetHashCode().Equals(otherRange.GetHashCode()));
/// to reduce the parsing and number of allocations for Strings and Uris
/// we cache the results after parsing.
/// </summary>
+ #pragma warning disable CA1067 // Override Equals because it implements IEquatable<T>; not overriding to avoid possible regressions in code that's working
internal sealed class ValidatedPartUri : Uri, IComparable<ValidatedPartUri>, IEquatable<ValidatedPartUri>
+#pragma warning restore CA1067
{
//------------------------------------------------------
//
string.Create(CultureInfo.InvariantCulture, $"{Index}: {(IsBoxed ? "boxed" : null)} {(InClosure ? "in closure" : null)}");
}
- internal readonly struct LocalDefinition
+ internal readonly struct LocalDefinition : IEquatable<LocalDefinition>
{
internal LocalDefinition(int localIndex, ParameterExpression parameter)
{
}
public int Index { get; }
+
public ParameterExpression Parameter { get; }
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- if (obj is LocalDefinition)
- {
- LocalDefinition other = (LocalDefinition)obj;
- return other.Index == Index && other.Parameter == Parameter;
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is LocalDefinition other && Equals(other);
- return false;
- }
+ public bool Equals(LocalDefinition other) => other.Index == Index && other.Parameter == Parameter;
- public override int GetHashCode()
- {
- if (Parameter == null)
- {
- return 0;
- }
- return Parameter.GetHashCode() ^ Index.GetHashCode();
- }
+ public override int GetHashCode() => Parameter is null ? 0 : Parameter.GetHashCode() ^ Index.GetHashCode();
}
internal sealed class LocalVariables
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
AddressListSort = (long)3355443225,
}
- public partial struct IPPacketInformation
+ public partial struct IPPacketInformation : System.IEquatable<System.Net.Sockets.IPPacketInformation>
{
private object _dummy;
private int _dummyPrimitive;
public System.Net.IPAddress Address { get { throw null; } }
public int Interface { get { throw null; } }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] object? comparand) { throw null; }
+ public bool Equals(System.Net.Sockets.IPPacketInformation other) { 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; }
namespace System.Net.Sockets
{
- public struct IPPacketInformation
+ public struct IPPacketInformation : IEquatable<IPPacketInformation>
{
private readonly IPAddress _address;
private readonly int _networkInterface;
_networkInterface = networkInterface;
}
- public IPAddress Address
- {
- get
- {
- return _address;
- }
- }
+ public IPAddress Address => _address;
- public int Interface
- {
- get
- {
- return _networkInterface;
- }
- }
+ public int Interface => _networkInterface;
- public static bool operator ==(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2)
- {
- return packetInformation1._networkInterface == packetInformation2._networkInterface &&
- ((packetInformation1._address == null && packetInformation2._address == null) ||
- (packetInformation1._address != null && packetInformation1._address.Equals(packetInformation2._address)));
- }
+ public static bool operator ==(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2) =>
+ packetInformation1.Equals(packetInformation2);
- public static bool operator !=(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2)
- {
- return !(packetInformation1 == packetInformation2);
- }
+ public static bool operator !=(IPPacketInformation packetInformation1, IPPacketInformation packetInformation2) =>
+ !packetInformation1.Equals(packetInformation2);
public override bool Equals([NotNullWhen(true)] object? comparand) =>
- comparand is IPPacketInformation other && this == other;
+ comparand is IPPacketInformation other && Equals(other);
- public override int GetHashCode()
- {
- return unchecked(_networkInterface.GetHashCode() * (int)0xA5555529) +
- (_address == null ? 0 : _address.GetHashCode());
- }
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(IPPacketInformation other) =>
+ _networkInterface == other._networkInterface &&
+ (_address is null ? other._address is null : _address.Equals(other._address));
+
+ public override int GetHashCode() =>
+ unchecked(_networkInterface.GetHashCode() * (int)0xA5555529) + (_address?.GetHashCode() ?? 0);
}
}
public void Equals_DefaultValues_Success()
{
Assert.Equal(default(IPPacketInformation), default(IPPacketInformation));
+
Assert.True(default(IPPacketInformation) == default(IPPacketInformation));
+ Assert.True(default(IPPacketInformation).Equals(default(IPPacketInformation)));
+
Assert.False(default(IPPacketInformation) != default(IPPacketInformation));
}
Assert.Equal(packetInfo, packetInfoCopy);
Assert.True(packetInfo == packetInfoCopy);
+ Assert.True(packetInfo.Equals(packetInfoCopy));
+ Assert.True(packetInfo.Equals((object)packetInfoCopy));
Assert.False(packetInfo != packetInfoCopy);
Assert.NotEqual(default, packetInfo);
Assert.False(packetInfo == default(IPPacketInformation));
+ Assert.False(packetInfo.Equals(default(IPPacketInformation)));
+ Assert.False(packetInfo.Equals((object)default(IPPacketInformation)));
Assert.True(packetInfo != default(IPPacketInformation));
int ignored = packetInfo.Interface; // just make sure it doesn't throw, nothing else to verify
// (ie, users could assign a new value to the old location).
[Serializable]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+#pragma warning disable CA1066 // adding IEquatable<T> implementation could change semantics of code like that in xunit that queries for IEquatable vs enumerating contents
public readonly struct ArraySegment<T> : IList<T>, IReadOnlyList<T>
+#pragma warning restore CA1066
{
+ // ArraySegment<T> doesn't implement IEquatable<T>, even though it provides a strongly-typed
+ // Equals(T), as that results in different comparison semantics than comparing item-by-item
+ // the elements returned from its IEnumerable<T> implementation. This then is a breaking change
+ // for usage like that in xunit's Assert.Equal, which will prioritize using an instance's IEquatable<T>
+ // over its IEnumerable<T>.
+
// Do not replace the array allocation with Array.Empty. We don't want to have the overhead of
// instantiating another generic type in addition to ArraySegment<T> for new type parameters.
#pragma warning disable CA1825
}
public override bool Equals([NotNullWhen(true)] object? obj) =>
- obj is ArraySegment<T> && Equals((ArraySegment<T>)obj);
+ obj is ArraySegment<T> other && Equals(other);
public bool Equals(ArraySegment<T> obj) =>
obj._array == _array && obj._offset == _offset && obj._count == _count;
#if ES_BUILD_STANDALONE
[System.Security.Permissions.HostProtection(MayLeakOnAbort = true)]
#endif
- internal struct EventDescriptor
+ internal readonly struct EventDescriptor : IEquatable<EventDescriptor>
{
#region private
[FieldOffset(0)]
using System.Runtime.InteropServices;
using Internal.Runtime.CompilerServices;
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
namespace System
{
// xxHash32 is used for the hash code.
using Internal.Runtime.CompilerServices;
#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
#if TARGET_64BIT
using nint_t = System.Int64;
#else
using System.Collections.Generic;
using System.Runtime.Versioning;
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
namespace System
{
// Because we have special type system support that says a boxed Nullable<T>
// 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.Reflection
{
- public readonly partial struct CustomAttributeNamedArgument
+ public readonly partial struct CustomAttributeNamedArgument : IEquatable<CustomAttributeNamedArgument>
{
public static bool operator ==(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => left.Equals(right);
public static bool operator !=(CustomAttributeNamedArgument left, CustomAttributeNamedArgument right) => !left.Equals(right);
return base.GetHashCode();
}
- public override bool Equals(object? obj)
- {
- return obj == (object)this;
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is CustomAttributeNamedArgument other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(CustomAttributeNamedArgument other) =>
+ _memberInfo == other._memberInfo &&
+ _value == other._value;
internal Type ArgumentType =>
_memberInfo is FieldInfo fi ?
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Text;
namespace System.Reflection
{
- public readonly partial struct CustomAttributeTypedArgument
+ public readonly partial struct CustomAttributeTypedArgument : IEquatable<CustomAttributeTypedArgument>
{
public static bool operator ==(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => left.Equals(right);
public static bool operator !=(CustomAttributeTypedArgument left, CustomAttributeTypedArgument right) => !left.Equals(right);
}
public override int GetHashCode() => base.GetHashCode();
- public override bool Equals(object? obj) => obj == (object)this;
+
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is CustomAttributeTypedArgument cata && Equals(cata);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(CustomAttributeTypedArgument other) => _value == other._value && _argumentType == other._argumentType;
public Type ArgumentType => _argumentType;
public object? Value => _value;
namespace System.Runtime.InteropServices
{
- public readonly struct ArrayWithOffset
+ public readonly struct ArrayWithOffset : IEquatable<ArrayWithOffset>
{
private readonly object? m_array;
private readonly int m_offset;
public override bool Equals([NotNullWhen(true)] object? obj)
{
- return obj is ArrayWithOffset && Equals((ArrayWithOffset)obj);
+ return obj is ArrayWithOffset awo && Equals(awo);
}
public bool Equals(ArrayWithOffset obj)
/// Pinned - same as Normal, but allows the address of the actual object to be taken.
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
- public partial struct GCHandle
+ public partial struct GCHandle : IEquatable<GCHandle>
{
// The actual integer handle value that the EE uses internally.
private IntPtr _handle;
public override int GetHashCode() => _handle.GetHashCode();
- public override bool Equals([NotNullWhen(true)] object? o) => o is GCHandle && _handle == ((GCHandle)o)._handle;
+ public override bool Equals([NotNullWhen(true)] object? o) => o is GCHandle other && Equals(other);
+
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(GCHandle other) => _handle == other._handle;
public static bool operator ==(GCHandle a, GCHandle b) => (nint)a._handle == (nint)b._handle;
using System.Diagnostics.CodeAnalysis;
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
namespace System.Runtime.Serialization
{
public readonly struct StreamingContext
/// </para>
/// </remarks>
[DebuggerDisplay("IsCancellationRequested = {IsCancellationRequested}")]
- public readonly struct CancellationToken
+ public readonly struct CancellationToken : IEquatable<CancellationToken>
{
// The backing TokenSource.
// if null, it implicitly represents the same thing as new CancellationToken(false).
}
}
- private struct Counts
+ private struct Counts : IEquatable<Counts>
{
private const byte SignalCountShift = 0;
private const byte WaiterCountShift = 32;
public Counts InterlockedCompareExchange(Counts newCounts, Counts oldCounts) =>
new Counts(Interlocked.CompareExchange(ref _data, newCounts._data, oldCounts._data));
- 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 static bool operator ==(Counts lhs, Counts rhs) => lhs.Equals(rhs);
+ public static bool operator !=(Counts lhs, Counts rhs) => !lhs.Equals(rhs);
- public override bool Equals([NotNullWhen(true)] object? obj) => obj is Counts counts && _data == counts._data;
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is Counts other && Equals(other);
+ public bool Equals(Counts other) => _data == other._data;
public override int GetHashCode() => (int)_data + (int)(_data >> 32);
}
/// <summary>
/// Tracks information on the number of threads we want/have in different states in our thread pool.
/// </summary>
- private struct ThreadCounts
+ private struct ThreadCounts : IEquatable<ThreadCounts>
{
// SOS's ThreadPool command depends on this layout
private const byte NumProcessingWorkShift = 0;
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([NotNullWhen(true)] object? obj) => obj is ThreadCounts other && _data == other._data;
+ public override bool Equals([NotNullWhen(true)] object? obj) => obj is ThreadCounts other && Equals(other);
+ public bool Equals(ThreadCounts other) => _data == other._data;
public override int GetHashCode() => (int)_data + (int)(_data >> 32);
}
}
/// <summary>
/// Tracks thread count information that is used when the <code>EnableWorkerTracking</code> config option is enabled.
/// </summary>
- private struct CountsOfThreadsProcessingUserCallbacks
+ private struct CountsOfThreadsProcessingUserCallbacks : IEquatable<CountsOfThreadsProcessingUserCallbacks>
{
private const byte CurrentShift = 0;
private const byte HighWatermarkShift = 16;
public static bool operator ==(
CountsOfThreadsProcessingUserCallbacks lhs,
- CountsOfThreadsProcessingUserCallbacks rhs) => lhs._data == rhs._data;
+ CountsOfThreadsProcessingUserCallbacks rhs) => lhs.Equals(rhs);
public static bool operator !=(
CountsOfThreadsProcessingUserCallbacks lhs,
- CountsOfThreadsProcessingUserCallbacks rhs) => lhs._data != rhs._data;
+ CountsOfThreadsProcessingUserCallbacks rhs) => !lhs.Equals(rhs);
public override bool Equals([NotNullWhen(true)] object? obj) =>
- obj is CountsOfThreadsProcessingUserCallbacks other && _data == other._data;
+ obj is CountsOfThreadsProcessingUserCallbacks other && Equals(other);
+
+ public bool Equals(CountsOfThreadsProcessingUserCallbacks other) => _data == other._data;
+
public override int GetHashCode() => (int)_data;
}
}
_daylightTransitionEnd.Equals(other._daylightTransitionEnd) &&
_daylightTransitionStart.Equals(other._daylightTransitionStart);
+ /// <summary>Indicates whether the current instance is equal to another instance.</summary>
+ /// <param name="obj">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is AdjustmentRule other && Equals(other);
+
public override int GetHashCode() => _dateStart.GetHashCode();
private AdjustmentRule(
using Internal.Runtime.CompilerServices;
#pragma warning disable SA1121 // explicitly using type aliases instead of built-in types
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
#if TARGET_64BIT
using nuint_t = System.UInt64;
#else
};
// Note: also used by XmlBinaryWriter
- internal struct QName
+ internal struct QName : IEquatable<QName>
{
public string prefix;
public string localname;
throw new XmlException(SR.XmlBinary_NoRemapPrefix, new string[] { prefix, this.namespaceUri, namespaceUri });
}
- public override int GetHashCode()
- {
- return this.prefix.GetHashCode() ^ this.localname.GetHashCode();
- }
+ public int GetNSHashCode() =>
+ HashCode.Combine(this.namespaceUri, this.localname);
- public int GetNSHashCode()
- {
- return HashCode.Combine(this.namespaceUri, this.localname);
- }
+ public override int GetHashCode() =>
+ this.prefix.GetHashCode() ^ this.localname.GetHashCode();
+ public override bool Equals([NotNullWhen(true)] object? other) =>
+ other is QName qname && Equals(qname);
- public override bool Equals([NotNullWhen(true)] object? other)
- {
- if (other is QName that)
- {
- return this == that;
- }
- return false;
- }
+ public bool Equals(QName other) =>
+ prefix == other.prefix &&
+ localname == other.localname &&
+ namespaceUri == other.namespaceUri;
- public override string ToString()
- {
- if (prefix.Length == 0)
- return this.localname;
- else
- return $"{this.prefix}:{this.localname}";
- }
+ public static bool operator ==(QName a, QName b) => a.Equals(b);
- public static bool operator ==(QName a, QName b)
- {
- return ((a.prefix == b.prefix)
- && (a.localname == b.localname)
- && (a.namespaceUri == b.namespaceUri));
- }
+ public static bool operator !=(QName a, QName b) => !a.Equals(b);
- public static bool operator !=(QName a, QName b)
- {
- return !(a == b);
- }
+ public override string ToString() =>
+ prefix.Length == 0 ? localname : $"{this.prefix}:{this.localname}";
};
private struct ElemInfo
namespace System.Xml.Xsl
{
- internal struct Int32Pair
+ internal readonly struct Int32Pair : IEquatable<Int32Pair>
{
- private readonly int _left;
- private readonly int _right;
-
public Int32Pair(int left, int right)
{
- _left = left;
- _right = right;
+ Left = left;
+ Right = right;
}
- public int Left { get { return _left; } }
- public int Right { get { return _right; } }
+ public int Left { get; }
+ public int Right { get; }
- public override bool Equals([NotNullWhen(true)] object? other)
- {
- if (other is Int32Pair)
- {
- Int32Pair o = (Int32Pair)other;
- return _left == o._left && _right == o._right;
- }
+ public override bool Equals([NotNullWhen(true)] object? other) =>
+ other is Int32Pair o && Equals(o);
- return false;
- }
+ public bool Equals(Int32Pair other) => Left == other.Left && Right == other.Right;
- public override int GetHashCode()
- {
- return _left.GetHashCode() ^ _right.GetHashCode();
- }
+ public override int GetHashCode() => Left.GetHashCode() ^ Right.GetHashCode();
}
- internal struct StringPair
+ internal readonly struct StringPair
{
- private readonly string _left;
- private readonly string _right;
-
public StringPair(string left, string right)
{
- _left = left;
- _right = right;
+ Left = left;
+ Right = right;
}
- public string Left { get { return _left; } }
- public string Right { get { return _right; } }
+ public string Left { get; }
+ public string Right { get; }
}
}
/// Cardinality of part of XmlQueryType
/// struct is being used because enum doesn't allow members
/// </summary>
- internal struct XmlQueryCardinality
+ internal readonly struct XmlQueryCardinality : IEquatable<XmlQueryCardinality>
{
private readonly int _value;
namespace System.Runtime.Caching
{
- internal struct ExpiresEntryRef
+ internal readonly struct ExpiresEntryRef : IEquatable<ExpiresEntryRef>
{
internal static readonly ExpiresEntryRef INVALID = new ExpiresEntryRef(0, 0);
_ref = ((((uint)pageIndex) << PAGE_SHIFT) | (((uint)(entryIndex)) & ENTRY_MASK));
}
- public override bool Equals(object value)
- {
- if (value is ExpiresEntryRef)
- {
- return _ref == ((ExpiresEntryRef)value)._ref;
- }
+ public override bool Equals(object value) => value is ExpiresEntryRef other && Equals(other);
- return false;
- }
+ public bool Equals(ExpiresEntryRef other) => _ref == other._ref;
- public static bool operator !=(ExpiresEntryRef r1, ExpiresEntryRef r2)
- {
- return r1._ref != r2._ref;
- }
- public static bool operator ==(ExpiresEntryRef r1, ExpiresEntryRef r2)
- {
- return r1._ref == r2._ref;
- }
+ public static bool operator ==(ExpiresEntryRef r1, ExpiresEntryRef r2) => r1.Equals(r2);
+ public static bool operator !=(ExpiresEntryRef r1, ExpiresEntryRef r2) => !r1.Equals(r2);
- public override int GetHashCode()
- {
- return (int)_ref;
- }
+ public override int GetHashCode() => (int)_ref;
- internal int PageIndex
- {
- get
- {
- int result = (int)(_ref >> PAGE_SHIFT);
- return result;
- }
- }
-
- internal int Index
- {
- get
- {
- int result = (int)(_ref & ENTRY_MASK);
- return result;
- }
- }
-
- internal bool IsInvalid
- {
- get
- {
- return _ref == 0;
- }
- }
+ internal int PageIndex => (int)(_ref >> PAGE_SHIFT);
+ internal int Index => (int)(_ref & ENTRY_MASK);
+ internal bool IsInvalid => _ref == 0;
}
[StructLayout(LayoutKind.Explicit)]
namespace System.Runtime.Caching
{
- internal struct UsageEntryRef
+ internal readonly struct UsageEntryRef : IEquatable<UsageEntryRef>
{
internal static readonly UsageEntryRef INVALID = new UsageEntryRef(0, 0);
_ref = ((((uint)pageIndex) << PAGE_SHIFT) | (((uint)(entryIndex)) & ENTRY_MASK));
}
- public override bool Equals(object value)
- {
- if (value is UsageEntryRef)
- {
- return _ref == ((UsageEntryRef)value)._ref;
- }
+ public override bool Equals(object value) =>
+ value is UsageEntryRef other && Equals(other);
- return false;
- }
- public static bool operator ==(UsageEntryRef r1, UsageEntryRef r2)
- {
- return r1._ref == r2._ref;
- }
+ public bool Equals(UsageEntryRef other) => _ref == other._ref;
- public static bool operator !=(UsageEntryRef r1, UsageEntryRef r2)
- {
- return r1._ref != r2._ref;
- }
+ public static bool operator ==(UsageEntryRef r1, UsageEntryRef r2) => r1.Equals(r2);
- public override int GetHashCode()
- {
- return (int)_ref;
- }
+ public static bool operator !=(UsageEntryRef r1, UsageEntryRef r2) => !r1.Equals(r2);
- internal int PageIndex
- {
- get
- {
- int result = (int)(_ref >> PAGE_SHIFT);
- return result;
- }
- }
+ public override int GetHashCode() => (int)_ref;
+
+ internal int PageIndex => (int)(_ref >> PAGE_SHIFT);
internal int Ref1Index
{
}
}
- internal bool IsRef1
- {
- get
- {
- return ((int)(sbyte)(_ref & ENTRY_MASK)) > 0;
- }
- }
+ internal bool IsRef1 => ((int)(sbyte)(_ref & ENTRY_MASK)) > 0;
- internal bool IsRef2
- {
- get
- {
- return ((int)(sbyte)(_ref & ENTRY_MASK)) < 0;
- }
- }
+ internal bool IsRef2 => ((int)(sbyte)(_ref & ENTRY_MASK)) < 0;
- internal bool IsInvalid
- {
- get
- {
- return _ref == 0;
- }
- }
+ internal bool IsInvalid => _ref == 0;
}
internal struct UsageEntryLink
{
public AllowReversePInvokeCallsAttribute() { }
}
- public readonly partial struct ArrayWithOffset
+ public readonly partial struct ArrayWithOffset : System.IEquatable<System.Runtime.InteropServices.ArrayWithOffset>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
Assert.Equal(expected, handle.Equals(other));
if (other is GCHandle otherHandle)
{
+ Assert.Equal(expected, handle.Equals(otherHandle));
Assert.Equal(expected, handle == otherHandle);
Assert.Equal(!expected, handle != otherHandle);
}
public MissingMethodException(string? className, string? methodName) { }
public override string Message { get { throw null; } }
}
- public partial struct ModuleHandle
+ public partial struct ModuleHandle : System.IEquatable<System.ModuleHandle>
{
private object _dummy;
private int _dummyPrimitive;
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 static System.TimeZoneInfo.AdjustmentRule CreateAdjustmentRule(System.DateTime dateStart, System.DateTime dateEnd, System.TimeSpan daylightDelta, System.TimeZoneInfo.TransitionTime daylightTransitionStart, System.TimeZoneInfo.TransitionTime daylightTransitionEnd, System.TimeSpan baseUtcOffsetDelta) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.TimeZoneInfo.AdjustmentRule? other) { throw null; }
+ public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { 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) { }
public CustomAttributeFormatException(string? message) { }
public CustomAttributeFormatException(string? message, System.Exception? inner) { }
}
- public readonly partial struct CustomAttributeNamedArgument
+ public readonly partial struct CustomAttributeNamedArgument : System.IEquatable<System.Reflection.CustomAttributeNamedArgument>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public System.Reflection.MemberInfo MemberInfo { get { throw null; } }
public string MemberName { get { throw null; } }
public System.Reflection.CustomAttributeTypedArgument TypedValue { get { throw null; } }
- public override bool Equals(object? obj) { throw null; }
+ public bool Equals(System.Reflection.CustomAttributeNamedArgument other) { 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.Reflection.CustomAttributeNamedArgument left, System.Reflection.CustomAttributeNamedArgument right) { throw null; }
public static bool operator !=(System.Reflection.CustomAttributeNamedArgument left, System.Reflection.CustomAttributeNamedArgument right) { throw null; }
public override string ToString() { throw null; }
}
- public readonly partial struct CustomAttributeTypedArgument
+ public readonly partial struct CustomAttributeTypedArgument : System.IEquatable<System.Reflection.CustomAttributeTypedArgument>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
public CustomAttributeTypedArgument(System.Type argumentType, object? value) { throw null; }
public System.Type ArgumentType { get { throw null; } }
public 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 bool Equals(System.Reflection.CustomAttributeTypedArgument other) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Reflection.CustomAttributeTypedArgument left, System.Reflection.CustomAttributeTypedArgument right) { throw null; }
public static bool operator !=(System.Reflection.CustomAttributeTypedArgument left, System.Reflection.CustomAttributeTypedArgument right) { throw null; }
public FieldOffsetAttribute(int offset) { }
public int Value { get { throw null; } }
}
- public partial struct GCHandle
+ public partial struct GCHandle : System.IEquatable<System.Runtime.InteropServices.GCHandle>
{
private int _dummyPrimitive;
public bool IsAllocated { get { 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([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; }
+ public bool Equals(System.Runtime.InteropServices.GCHandle other) { throw null; }
public void Free() { }
public static System.Runtime.InteropServices.GCHandle FromIntPtr(System.IntPtr value) { throw null; }
public override int GetHashCode() { throw null; }
}
namespace System.Threading
{
- public readonly partial struct CancellationToken
+ public readonly partial struct CancellationToken : System.IEquatable<System.Threading.CancellationToken>
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
}
[Fact]
+ public static void Test_CustomAttributeTypedArgument_Equals()
+ {
+ Type t = typeof(MyClass);
+ foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(t))
+ {
+ foreach (CustomAttributeTypedArgument cata in cad.ConstructorArguments)
+ {
+ Assert.True(cata.Equals(cata));
+ Assert.True(cata.Equals((object)cata));
+
+ var notEqualArgument = new CustomAttributeTypedArgument(new [] { new CustomAttributeTypedArgument(0) });
+ Assert.False(cata.Equals(notEqualArgument));
+ Assert.False(cata.Equals((object)notEqualArgument));
+
+ return;
+ }
+ }
+
+ Assert.True(false, "Expected to find MyAttr Attribute");
+ }
+
+ [Fact]
public static void Test_CustomAttributeTypedArgument_ToString()
{
var argument = new CustomAttributeTypedArgument(new [] { new CustomAttributeTypedArgument(0) });
{
public void Stop(bool stopDependentServices) { }
}
+ public readonly partial struct SessionChangeDescription : System.IEquatable<System.ServiceProcess.SessionChangeDescription>
+ {
+ }
}
<IsPartialFacadeAssembly Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETFramework'">true</IsPartialFacadeAssembly>
<OmitResources Condition="'$(IsPartialFacadeAssembly)' == 'true'">true</OmitResources>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' != 'true'">SR.PlatformNotSupported_ServiceController</GeneratePlatformNotSupportedAssemblyMessage>
+ <!-- we cannot add API on .NETStandard since it would be absent on .NETFramework, suppress warnings that require API changes -->
+ <NoWarn Condition="$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)')) == '.NETStandard'">$(NoWarn);CA1066</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
namespace System.ServiceProcess
{
public readonly struct SessionChangeDescription
+#if NETCOREAPP
+ : IEquatable<SessionChangeDescription>
+#endif
{
internal SessionChangeDescription(SessionChangeReason reason, int id)
{
public int SessionId { get; }
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- if (!(obj is SessionChangeDescription))
- {
- return false;
- }
+ public override int GetHashCode() =>
+ (int)Reason ^ SessionId;
- return Equals((SessionChangeDescription)obj);
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is SessionChangeDescription other && Equals(other);
- public override int GetHashCode()
- {
- return (int)Reason ^ SessionId;
- }
+ public bool Equals(SessionChangeDescription changeDescription) =>
+ (Reason == changeDescription.Reason) &&
+ (SessionId == changeDescription.SessionId);
- public bool Equals(SessionChangeDescription changeDescription)
- {
- return (Reason == changeDescription.Reason) && (SessionId == changeDescription.SessionId);
- }
+ public static bool operator ==(SessionChangeDescription a, SessionChangeDescription b) =>
+ a.Equals(b);
- public static bool operator ==(SessionChangeDescription a, SessionChangeDescription b)
- {
- return a.Equals(b);
- }
-
- public static bool operator !=(SessionChangeDescription a, SessionChangeDescription b)
- {
- return !a.Equals(b);
- }
+ public static bool operator !=(SessionChangeDescription a, SessionChangeDescription b) =>
+ !a.Equals(b);
}
}
void CompleteSkip(int skipped);
void LoadResource([MarshalAs(UnmanagedType.LPWStr)] string resource, ref string mediaType, out IStream stream);
}
+
[StructLayout(LayoutKind.Sequential)]
- internal struct SpeechEventSapi
+ internal struct SpeechEventSapi : IEquatable<SpeechEventSapi>
{
public short EventId;
public short ParameterType;
public long AudioStreamOffset;
public IntPtr Param1; // Always just a numeric type - contains no unmanaged resources so does not need special clean-up.
public IntPtr Param2; // Can be a numeric type, or pointer to string or object. Use SafeSapiLParamHandle to cleanup.
- public static bool operator ==(SpeechEventSapi event1, SpeechEventSapi event2)
- {
- return event1.EventId == event2.EventId && event1.ParameterType == event2.ParameterType && event1.StreamNumber == event2.StreamNumber && event1.AudioStreamOffset == event2.AudioStreamOffset && event1.Param1 == event2.Param1 && event1.Param2 == event2.Param2;
- }
- public static bool operator !=(SpeechEventSapi event1, SpeechEventSapi event2)
- {
- return !(event1 == event2);
- }
- public override bool Equals(object obj)
- {
- if (!(obj is SpeechEventSapi))
- {
- return false;
- }
- return this == (SpeechEventSapi)obj;
- }
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
+ public static bool operator ==(SpeechEventSapi event1, SpeechEventSapi event2) => event1.Equals(event2);
+ public static bool operator !=(SpeechEventSapi event1, SpeechEventSapi event2) => !event1.Equals(event2);
+
+ public override bool Equals(object obj) =>
+ obj is SpeechEventSapi other && Equals(other);
+
+ public bool Equals(SpeechEventSapi other) =>
+ EventId == other.EventId &&
+ ParameterType == other.ParameterType &&
+ StreamNumber == other.StreamNumber &&
+ AudioStreamOffset == other.AudioStreamOffset &&
+ Param1 == other.Param1 &&
+ Param2 == other.Param2;
+
+ public override int GetHashCode() => base.GetHashCode();
}
#endregion
namespace System.Text
{
- internal readonly struct Rune
+ internal readonly struct Rune : IEquatable<Rune>
{
private const int MaxUtf16CharsPerRune = 2; // supplementary plane code points are encoded as 2 UTF-16 code units
namespace System.Text.RegularExpressions.Symbolic
{
- internal readonly struct SymbolicMatch
+ internal readonly struct SymbolicMatch : IEquatable<SymbolicMatch>
{
/// <summary>Indicates failure to find a match.</summary>
internal static SymbolicMatch NoMatch => new SymbolicMatch(-1, -1);
}
public int Index { get; }
+
public int Length { get; }
+
public bool Success => Index >= 0;
public static bool operator ==(SymbolicMatch left, SymbolicMatch right) =>
- left.Index == right.Index && left.Length == right.Length;
+ left.Equals(right);
public static bool operator !=(SymbolicMatch left, SymbolicMatch right) =>
- !(left == right);
+ !left.Equals(right);
public override bool Equals([NotNullWhen(true)] object? obj) =>
- obj is SymbolicMatch other && this == other;
+ obj is SymbolicMatch other && Equals(other);
+
+ public bool Equals(SymbolicMatch other) => Index == other.Index && Length == other.Length;
public override int GetHashCode() => HashCode.Combine(Index, Length);
}
namespace System.Text.RegularExpressions.Symbolic
{
/// <summary>Misc information of structural properties of a <see cref="SymbolicRegexNode{S}"/> that is computed bottom up.</summary>
- internal readonly struct SymbolicRegexInfo
+ internal readonly struct SymbolicRegexInfo : IEquatable<SymbolicRegexInfo>
{
private const uint IsAlwaysNullableMask = 1;
private const uint StartsWithLineAnchorMask = 2;
containsSomeCharacter: info.ContainsSomeCharacter,
isLazy: info.IsLazy);
- public override bool Equals(object? obj) => obj is SymbolicRegexInfo i && i._info == _info;
+ public override bool Equals(object? obj) => obj is SymbolicRegexInfo i && Equals(i);
+
+ public bool Equals(SymbolicRegexInfo other) => _info == other._info;
public override int GetHashCode() => _info.GetHashCode();
public static T EnsureInitialized<T>([System.Diagnostics.CodeAnalysis.NotNullAttribute] ref T? target, System.Func<T> valueFactory) where T : class { throw null; }
public static T EnsureInitialized<T>([System.Diagnostics.CodeAnalysis.NotNullAttribute] ref T? target, [System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute("syncLock")] ref object? syncLock, System.Func<T> valueFactory) where T : class { throw null; }
}
- public partial struct LockCookie
+ public partial struct LockCookie : System.IEquatable<System.Threading.LockCookie>
{
private int _dummyPrimitive;
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
/// Stores the lock state of a <see cref="ReaderWriterLock"/> before its lock state is changed, such that the lock state may
/// later be restored.
/// </summary>
- public struct LockCookie
+ public struct LockCookie : IEquatable<LockCookie>
{
internal LockCookieFlags _flags;
internal ushort _readerLevel;
internal ushort _writerLevel;
internal int _threadID;
- public override int GetHashCode()
- {
- return (int)_flags + _readerLevel + _writerLevel + _threadID;
- }
+ public override int GetHashCode() =>
+ (int)_flags + _readerLevel + _writerLevel + _threadID;
- public override bool Equals([NotNullWhen(true)] object? obj)
- {
- return obj is LockCookie && Equals((LockCookie)obj);
- }
+ public override bool Equals([NotNullWhen(true)] object? obj) =>
+ obj is LockCookie other && Equals(other);
- public bool Equals(LockCookie obj)
- {
- return
- _flags == obj._flags &&
- _readerLevel == obj._readerLevel &&
- _writerLevel == obj._writerLevel &&
- _threadID == obj._threadID;
- }
+ public bool Equals(LockCookie obj) =>
+ _flags == obj._flags &&
+ _readerLevel == obj._readerLevel &&
+ _writerLevel == obj._writerLevel &&
+ _threadID == obj._threadID;
- public static bool operator ==(LockCookie a, LockCookie b)
- {
- return a.Equals(b);
- }
+ public static bool operator ==(LockCookie a, LockCookie b) => a.Equals(b);
- public static bool operator !=(LockCookie a, LockCookie b)
- {
- return !(a == b);
- }
+ public static bool operator !=(LockCookie a, LockCookie b) => !a.Equals(b);
}
}
public TransactionManagerCommunicationException(string? message) { }
public TransactionManagerCommunicationException(string? message, System.Exception? innerException) { }
}
- public partial struct TransactionOptions
+ public partial struct TransactionOptions : System.IEquatable<System.Transactions.TransactionOptions>
{
- private int _dummyPrimitive;
+ private readonly int _dummyPrimitive;
public System.Transactions.IsolationLevel IsolationLevel { get { throw null; } set { } }
public System.TimeSpan Timeout { get { throw null; } set { } }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
+ public bool Equals(System.Transactions.TransactionOptions other) { 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; }
namespace System.Transactions
{
- public struct TransactionOptions
+ public struct TransactionOptions : IEquatable<TransactionOptions>
{
private TimeSpan _timeout;
private IsolationLevel _isolationLevel;
public override bool Equals([NotNullWhen(true)] object? obj) => obj is TransactionOptions transactionOptions && Equals(transactionOptions);
- private bool Equals(TransactionOptions other) =>
+ /// <summary>Indicates whether the current instance is equal to another instance of the same type.</summary>
+ /// <param name="other">An instance to compare with this instance.</param>
+ /// <returns>true if the current instance is equal to the other instance; otherwise, false.</returns>
+ public bool Equals(TransactionOptions other) =>
_timeout == other._timeout &&
_isolationLevel == other._isolationLevel;
namespace Mono
{
- internal unsafe struct RuntimeClassHandle
+ internal unsafe struct RuntimeClassHandle : IEquatable<RuntimeClassHandle>
{
private readonly RuntimeStructs.MonoClass* value;
}
}
- internal struct RuntimeEventHandle
+ internal struct RuntimeEventHandle : IEquatable<RuntimeEventHandle>
{
private readonly IntPtr value;
}
}
- internal struct RuntimePropertyHandle
+ internal struct RuntimePropertyHandle : IEquatable<RuntimePropertyHandle>
{
private readonly IntPtr value;
namespace System
{
- public struct ModuleHandle
+ public struct ModuleHandle : IEquatable<ModuleHandle>
{
private readonly IntPtr value;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+#pragma warning disable CA1066 // Implement IEquatable when overriding Object.Equals
+
namespace System
{
public partial struct Nullable<T>
namespace Microsoft.WebAssembly.Diagnostics
{
- public struct SessionId
+ public struct SessionId : IEquatable<SessionId>
{
public readonly string sessionId;
// hashset treats 0 as unset
public override int GetHashCode() => sessionId?.GetHashCode() ?? -1;
- public override bool Equals(object obj) => (obj is SessionId) ? ((SessionId)obj).sessionId == sessionId : false;
+ public override bool Equals(object obj) => obj is SessionId other && Equals(other);
+
+ public bool Equals(SessionId other) => other.sessionId == sessionId;
public static bool operator ==(SessionId a, SessionId b) => a.sessionId == b.sessionId;
public override string ToString() => $"session-{sessionId}";
}
- public struct MessageId
+ public struct MessageId : IEquatable<MessageId>
{
public readonly string sessionId;
public readonly int id;
public override int GetHashCode() => (sessionId?.GetHashCode() ?? 0) ^ id.GetHashCode();
- public override bool Equals(object obj) => (obj is MessageId) ? ((MessageId)obj).sessionId == sessionId && ((MessageId)obj).id == id : false;
+ public override bool Equals(object obj) => obj is MessageId other && Equals(other);
+
+ public bool Equals(MessageId other) => other.sessionId == sessionId && other.id == id;
}
internal class DotnetObjectId
private static void Error (string msg) => throw new LogAsErrorException(msg);
}
+#pragma warning disable CA1067
internal sealed class PInvoke : IEquatable<PInvoke>
+#pragma warning restore CA1067
{
public PInvoke(string entryPoint, string module, MethodInfo method)
{