Defines a diagnostic with strongly-typed parameters.
Implements
Namespace: Metalama.Framework.Diagnostics
Assembly: Metalama.Framework.dll
Syntax
public class DiagnosticDefinition<T> : IDiagnosticDefinition where T : notnullType 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 |
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. |
| 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. |