Diagnostic Class
Represents a diagnostic produced while reading source text.
public sealed class Diagnostic : IEquatable<Diagnostic>Example
var tree = XmlSyntaxTree.ParseText("<root><child></root>");
var messages = new List<string>();
foreach (var diagnostic in tree.GetDiagnostics())
{
messages.Add($"{diagnostic.Id} at {diagnostic.Location}: {diagnostic.Message}");
}
Assert.Equal(["XML0001 at (0,6)-(0,13): Missing end tag for 'child'."], messages);- Implements
Constructors
| Name | Description |
|---|---|
| Diagnostic(string, string, DiagnosticSeverity, Location) | Represents a diagnostic produced while reading source text. |
Diagnostic(string, string, DiagnosticSeverity, Location)
Diagnostic.csRepresents a diagnostic produced while reading source text.
public Diagnostic(string Id, string Message, DiagnosticSeverity Severity, Location Location)Parameters
IdstringMessagestringSeverityDiagnosticSeverityLocationLocation
Example
var tree = XmlSyntaxTree.ParseText("<root><child></root>");
var messages = new List<string>();
foreach (var diagnostic in tree.GetDiagnostics())
{
messages.Add($"{diagnostic.Id} at {diagnostic.Location}: {diagnostic.Message}");
}
Assert.Equal(["XML0001 at (0,6)-(0,13): Missing end tag for 'child'."], messages);Properties
| Name | Description |
|---|---|
| Id | |
| Location | |
| Message | |
| Severity |
Location
Diagnostic.csMessage
Diagnostic.csSeverity
Diagnostic.csMethods
| Name | Description |
|---|---|
| Create(DiagnosticDescriptor, Location, object?[]) | Creates a diagnostic from a descriptor, formatting DiagnosticDescriptor.MessageFormat with arguments. |
| Deconstruct(string, string, DiagnosticSeverity, Location) | |
| Equals(Diagnostic?) | |
| Equals(object?) | |
| GetHashCode() | |
| ToString() |
Create(DiagnosticDescriptor, Location, object?[])
Diagnostic.csCreates a diagnostic from a descriptor, formatting DiagnosticDescriptor.MessageFormat with arguments.
public static Diagnostic Create(DiagnosticDescriptor descriptor, Location location, params object?[] arguments)Parameters
descriptorDiagnosticDescriptor- The descriptor supplying the id, message template, and severity.
locationLocation- Where the diagnostic applies.
argumentsobject?[]- The values to substitute into the message template. The template is used verbatim when there is none.
Returns
Exceptions
ArgumentNullExceptiondescriptororlocationisnull.
Deconstruct(string, string, DiagnosticSeverity, Location)
public void Deconstruct(out string Id, out string Message, out DiagnosticSeverity Severity, out Location Location)Parameters
IdstringMessagestringSeverityDiagnosticSeverityLocationLocation
No documentation is available.
Equals overloads
Equals(Diagnostic?)
public bool Equals(Diagnostic? other)No documentation is available.
Equals(object?)
GetHashCode()
ToString()
Operators
| Name | Description |
|---|---|
| operator ==(Diagnostic?, Diagnostic?) | |
| operator !=(Diagnostic?, Diagnostic?) |
operator ==(Diagnostic?, Diagnostic?)
public static bool operator ==(Diagnostic? left, Diagnostic? right)No documentation is available.
operator !=(Diagnostic?, Diagnostic?)
public static bool operator !=(Diagnostic? left, Diagnostic? right)No documentation is available.