How to Suppress Diagnostic
Suppression of diagnostics is useful to suppress rare cases that are not or cannot be covered by an analyzer.
This approach should not be used as a replacement for configuration of analyzers since analyzers that produce diagnostics still execute even if diagnostics are suppressed.
Suppress Diagnostic for a Declaration
using System.Diagnostics.CodeAnalysis;
class C
{
[SuppressMessage("Readability", "RCS1008", Justification = "<Pending>")]
void M()
{
var x = Foo(); // no RCS1008 here
}
}
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Readability", "RCS1008", Justification = "<Pending>", Scope = "member", Target = "~M:C.M")]
class C
{
void M()
{
var x = Foo(); // no RCS1008 here
}
}
Suppress Diagnostic for Selected Lines
using System.Diagnostics.CodeAnalysis;
class C
{
void M()
{
#pragma warning disable RCS1008
var x = Foo(); // no RCS1008 here
#pragma warning restore RCS1008
}
}
Suppress Diagnostic for Namespace
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Readability", "RCS1008", Justification = "<Pending>", Scope = "NamespaceAndDescendants", Target = "N1.N2")]
namespace N1.N2
{
class C
{
void M()
{
var x = Foo(); // no RCS1008 here
}
}
}