Open sandboxFocus

Class DiagnosticDefinition<T>

Defines a diagnostic with strongly-typed parameters.

Inheritance
DiagnosticDefinition<T>
Namespace: Metalama.Framework.Diagnostics
Assembly: Metalama.Framework.dll
Syntax
public class DiagnosticDefinition<T> : IDiagnosticDefinition where T : notnull
Type Parameters
Name Description
T

The type of arguments: a single type for one parameter, or a tuple type for multiple parameters. Alternatively, you can use object[] for weakly-typed parameters.

Remarks

Diagnostic definitions must be declared as static fields in compile-time classes (such as aspect classes, fabric classes, or other compile-time helper classes). They specify a unique ID, severity level, and a message format string that uses the standard .NET string formatting syntax.

To report a diagnostic with parameters, first call WithArguments(T) to create an IDiagnostic instance with the parameter values, then pass it to Report(IDiagnostic).

For a single parameter, set T to the parameter type (e.g., DiagnosticDefinition<string>). For multiple parameters, use a tuple (e.g., DiagnosticDefinition<(int, string)>). For weakly-typed parameters, use DiagnosticDefinition<object[]>. For diagnostics without parameters, use DiagnosticDefinition instead.

Examples

private static readonly DiagnosticDefinition<string> _fieldNotFoundError = new(
"MY002",
Severity.Error,
"The field '{0}' was not found in type.");

// In BuildAspect: builder.Diagnostics.Report(_fieldNotFoundError.WithArguments("_logger"));

Constructors

Name Description
DiagnosticDefinition(string, Severity, string, string?, string?)

Initializes a new instance of the DiagnosticDefinition<T> class.

Properties

Name Description
Category

Gets the category of the diagnostic (e.g. your product name).

Id

Gets an unique identifier for the diagnostic (e.g. MY001).

MessageFormat

Gets the formatting string of the diagnostic message.

Severity

Gets the severity of the diagnostic.

Title

Gets a short title describing the diagnostic. This title is typically described in the solution explorer of the IDE and does not contain formatting string parameters.

Methods

Name Description
ToString()
WithArguments(T)

Creates a diagnostic instance with the specified arguments.

Extension Methods

See Also