-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add IEquatable<T> to public Equals-overriding value types to enable CA1066/1067 #63687
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsCA1066 validates that types that override Equals also implement These types already provide a Microsoft.Extensions.Logging.EventId
System.ArraySegment<T>
System.Collections.Specialized.BitVector32.Section
System.Diagnostics.CounterSample
System.Diagnostics.SymbolStore.SymbolToken
System.ModuleHandle
System.Runtime.InteropServices.ArrayWithOffset
System.ServiceProcess.SessionChangeDescription
System.Threading.CancellationToken
System.Threading.LockCookie These types need both the System.Collections.Specialized.BitVector32
System.ComponentModel.Composition.ReflectionModel.LazyMemberInfo
System.ComponentModel.Design.Serialization.MemberRelationship
System.Data.SqlTypes.SqlBinary
System.Data.SqlTypes.SqlBoolean
System.Data.SqlTypes.SqlByte
System.Data.SqlTypes.SqlDateTime
System.Data.SqlTypes.SqlDecimal
System.Data.SqlTypes.SqlDouble
System.Data.SqlTypes.SqlGuid
System.Data.SqlTypes.SqlInt16
System.Data.SqlTypes.SqlInt32
System.Data.SqlTypes.SqlInt64
System.Data.SqlTypes.SqlMoney
System.Data.SqlTypes.SqlSingle
System.Data.SqlTypes.SqlString
System.Drawing.CharacterRange
System.Net.Sockets.IPPacketInformation
System.Reflection.CustomAttributeNamedArgument
System.Reflection.CustomAttributeTypedArgument
System.Runtime.InteropServices.GCHandle
System.Transactions.TransactionOptions These types implement System.TimeZoneInfo.AdjustmentRule These types override Equals but are special in some way (e.g. throwing a NotSupportedException from Equals) and I believe should just have CA1066 suppressed rather than adding the interface implementation: System.HashCode
System.Nullable<T> These types are part of libraries that are deprecated or are in the process of being deprecated and so I believe should just have CA1066 suppressed: System.Runtime.Serialization.StreamingContext
|
Looks good as proposed. (Declare on the duck-typeable ones, provide the implementation on the semantic-providing ones, fix AdjustmentRule, and suppress on the three outliers) |
In implementing this, I found at least one case that's a problem. This popped with |
CA1066 validates that value types that override Equals also implement
IEquatable<T>
(and CA1067 validates that types that implementIEquatable<T>
overrideEquals
). We have a bunch of types that don't follow that guidance, which is particularly an issue for structs where the argument will be boxed to call Equals. We've been addingIEquatable<T>
to such types as they've been requested, but after a bunch of them have come through API review, we generally agreed to just blanket add them all to all types that violate the rule. This issue outlines those types.These types already provide a
public bool Equals(T other)
method and just need to implement theIEquatable<T>
interface:These types need both the
IEquatable<T>
interface implementation and apublic bool Equals(T other)
method added:These types implement
IEquatable<T>
but don't overrideEquals(object)
and so need an override:These types override Equals but are special in some way (e.g. throwing a NotSupportedException from Equals) and I believe should just have CA1066 suppressed rather than adding the interface implementation:
These types are part of libraries that are deprecated or are in the process of being deprecated and so I believe should just have CA1066 suppressed:
The text was updated successfully, but these errors were encountered: