Skip to content

Commit

Permalink
Implement IEquatable<T> on value types overriding Equals (and enable …
Browse files Browse the repository at this point in the history
…CA1066/1077)
  • Loading branch information
stephentoub committed Jan 19, 2022
1 parent 8604989 commit 26b566e
Show file tree
Hide file tree
Showing 109 changed files with 692 additions and 868 deletions.
4 changes: 2 additions & 2 deletions eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ dotnet_diagnostic.CA1064.severity = none
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,6 @@
<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" />
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ public int this[int index]
}
}

#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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
}
}

public unsafe partial struct ModuleHandle
public unsafe partial struct ModuleHandle : IEquatable<ModuleHandle>
{
#region Public Static Members
public static readonly ModuleHandle EmptyHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace System
{
public struct ModuleHandle
public struct ModuleHandle : IEquatable<ModuleHandle>
{
public static readonly ModuleHandle EmptyHandle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
// - 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

using Internal.Reflection.Tracing;

#pragma warning disable CA1067 // override Equals because it implements IEquatable<T>

namespace System.Reflection.Runtime.TypeInfos
{
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void EmitHandle(RecordDef record)
{
string handleName = $"{record.Name}Handle";

OpenScope($"public partial struct {handleName}");
OpenScope($"public partial struct {handleName} : IEquatable<{handleName}>");

OpenScope("public override bool Equals(object obj)");
WriteLine($"if (obj is {handleName})");
Expand Down
Loading

0 comments on commit 26b566e

Please sign in to comment.