Open sandboxFocus

Class SuppressionDefinition

Defines a diagnostic suppression that can be applied by aspect code to prevent specific compiler or analyzer diagnostics from being reported in target code.

Inheritance
SuppressionDefinition
Implements
Namespace: Metalama.Framework.Diagnostics
Assembly: Metalama.Framework.dll
Syntax
[CompileTime]
public sealed class SuppressionDefinition : ISuppression
Remarks

Suppression definitions must be declared as static fields in compile-time classes (such as aspect classes, fabric classes, or other compile-time helper classes), similar to DiagnosticDefinition. They specify the diagnostic ID to suppress (e.g., "CS0169") and optionally a justification for the suppression.

Suppressions are applied using Suppress(ISuppression) or Suppress(ISuppression, IDeclaration, IDiagnosticSource) within a declaration scope. This prevents the C# compiler or analyzers from reporting diagnostics that become irrelevant due to aspect transformations.

Use WithFilter(Func<ISuppressibleDiagnostic, bool>) to create a filtered suppression that only suppresses diagnostics matching specific criteria, such as diagnostics with particular message text or arguments.

Examples

private static readonly SuppressionDefinition _suppressUnusedField = new(
"CS0169",
"Field is used in generated code");

// In BuildAspect: builder.Diagnostics.Suppress(_suppressUnusedField);

Constructors

Name Description
SuppressionDefinition(string, string?)

Initializes a new instance of the SuppressionDefinition class.

Properties

Name Description
Justification

Gets the justification for the suppression.

SuppressedDiagnosticId

Gets the ID of the diagnostic to be suppressed (e.g. CS0169).

Methods

Name Description
ToString()
WithFilter(Func<ISuppressibleDiagnostic, bool>)

Creates a filtered suppression that only suppresses diagnostics matching the specified predicate.

Extension Methods

See Also