Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public override string GetMessage(IFormatProvider formatProvider = null)

public override bool Equals(Diagnostic obj)
{
var other = obj as SuppressionDiagnostic;
if (other == null)
if (ReferenceEquals(this, obj))
{
return false;
return true;
}

if (ReferenceEquals(this, other))
var other = obj as SuppressionDiagnostic;
if (other == null)
{
return true;
return false;
}

return Equals(_originalDiagnostic, other._originalDiagnostic) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ public override ImmutableDictionary<string, string> Properties

public override bool Equals(Diagnostic? obj)
{
var other = obj as DiagnosticWithProgrammaticSuppression;
if (other == null)
if (ReferenceEquals(this, obj))
{
return false;
return true;
}

if (ReferenceEquals(this, other))
var other = obj as DiagnosticWithProgrammaticSuppression;
if (other == null)
{
return true;
return false;
}

return Equals(_originalUnsuppressedDiagnostic, other._originalUnsuppressedDiagnostic) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ internal DiagnosticDescriptor(

public bool Equals(DiagnosticDescriptor? other)
{
if (ReferenceEquals(this, other))
{
return true;
}

return
other != null &&
this.Category == other.Category &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public override bool Equals(object? obj)

public override bool Equals(Diagnostic? obj)
{
if (this == obj)
if (ReferenceEquals(this, obj))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public override ImmutableDictionary<string, string> Properties

public override bool Equals(Diagnostic? obj)
{
if (ReferenceEquals(this, obj))
{
return true;
}

var other = obj as SimpleDiagnostic;
if (other == null)
{
Expand Down
33 changes: 32 additions & 1 deletion src/Compilers/Core/Portable/DiagnosticAnalyzer/Suppression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// Programmatic suppression of a <see cref="Diagnostic"/> by a <see cref="DiagnosticSuppressor"/>.
/// </summary>
public struct Suppression
public struct Suppression : IEquatable<Suppression>
{
private Suppression(SuppressionDescriptor descriptor, Diagnostic suppressedDiagnostic)
{
Expand Down Expand Up @@ -48,5 +50,34 @@ public static Suppression Create(SuppressionDescriptor descriptor, Diagnostic su
/// Diagnostic suppressed by this suppression.
/// </summary>
public Diagnostic SuppressedDiagnostic { get; }

public static bool operator ==(Suppression left, Suppression right)
{
return left.Equals(right);
}

public static bool operator !=(Suppression left, Suppression right)
{
return !(left == right);
}

public override bool Equals(object obj)
{
return obj is Suppression suppression
&& Equals(suppression);
}

public bool Equals(Suppression other)
{
return EqualityComparer<SuppressionDescriptor>.Default.Equals(Descriptor, other.Descriptor)
&& EqualityComparer<Diagnostic>.Default.Equals(SuppressedDiagnostic, other.SuppressedDiagnostic);
}

public override int GetHashCode()
{
return Hash.Combine(
EqualityComparer<SuppressionDescriptor>.Default.GetHashCode(Descriptor),
EqualityComparer<Diagnostic>.Default.GetHashCode(SuppressedDiagnostic));
}
}
}
5 changes: 5 additions & 0 deletions src/Compilers/Core/Portable/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Microsoft.CodeAnalysis.CommandLineSourceFile.CommandLineSourceFile(string path, bool isScript, bool isInputRedirected) -> void
Microsoft.CodeAnalysis.CommandLineSourceFile.IsInputRedirected.get -> bool
Microsoft.CodeAnalysis.Diagnostics.Suppression.Equals(Microsoft.CodeAnalysis.Diagnostics.Suppression other) -> bool
Microsoft.CodeAnalysis.GeneratorAttribute
Microsoft.CodeAnalysis.GeneratorAttribute.GeneratorAttribute() -> void
Microsoft.CodeAnalysis.GeneratorDriver
Expand All @@ -25,5 +26,9 @@ Microsoft.CodeAnalysis.SourceGeneratorContext.ReportDiagnostic(Microsoft.CodeAna
Microsoft.CodeAnalysis.SourceGeneratorContext.SyntaxReceiver.get -> Microsoft.CodeAnalysis.ISyntaxReceiver
Microsoft.CodeAnalysis.SyntaxReceiverCreator
override Microsoft.CodeAnalysis.Diagnostics.AnalyzerFileReference.GetGenerators() -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ISourceGenerator>
override Microsoft.CodeAnalysis.Diagnostics.Suppression.Equals(object obj) -> bool
override Microsoft.CodeAnalysis.Diagnostics.Suppression.GetHashCode() -> int
static Microsoft.CodeAnalysis.Diagnostics.Suppression.operator !=(Microsoft.CodeAnalysis.Diagnostics.Suppression left, Microsoft.CodeAnalysis.Diagnostics.Suppression right) -> bool
static Microsoft.CodeAnalysis.Diagnostics.Suppression.operator ==(Microsoft.CodeAnalysis.Diagnostics.Suppression left, Microsoft.CodeAnalysis.Diagnostics.Suppression right) -> bool
virtual Microsoft.CodeAnalysis.Diagnostics.AnalyzerReference.GetGenerators() -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.ISourceGenerator>
const Microsoft.CodeAnalysis.WellKnownDiagnosticTags.CustomObsolete = "CustomObsolete" -> string