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

NameDescription
Diagnostic(string, string, DiagnosticSeverity, Location)Represents a diagnostic produced while reading source text.

Diagnostic(string, string, DiagnosticSeverity, Location)

Diagnostic.cs

Represents a diagnostic produced while reading source text.

public Diagnostic(string Id, string Message, DiagnosticSeverity Severity, Location Location)

Parameters

Id string
Message string
Severity DiagnosticSeverity
Location Location

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

NameDescription
Id
Location
Message
Severity
public string Id { get; init; }

Property value

string

No documentation is available.

public Location Location { get; init; }

Property value

Location

No documentation is available.

public string Message { get; init; }

Property value

string

No documentation is available.

public DiagnosticSeverity Severity { get; init; }

Property value

DiagnosticSeverity

No documentation is available.

Methods

NameDescription
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.cs

Creates a diagnostic from a descriptor, formatting DiagnosticDescriptor.MessageFormat with arguments.

public static Diagnostic Create(DiagnosticDescriptor descriptor, Location location, params object?[] arguments)

Parameters

descriptor DiagnosticDescriptor
The descriptor supplying the id, message template, and severity.
location Location
Where the diagnostic applies.
arguments object?[]
The values to substitute into the message template. The template is used verbatim when there is none.

Returns

Diagnostic

Exceptions

ArgumentNullException
descriptor or location is null.

Deconstruct(string, string, DiagnosticSeverity, Location)

public void Deconstruct(out string Id, out string Message, out DiagnosticSeverity Severity, out Location Location)

Parameters

Id string
Message string
Severity DiagnosticSeverity
Location Location

No documentation is available.

Equals overloads

Equals(Diagnostic?)

public bool Equals(Diagnostic? other)
Parameters
other Diagnostic?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

ToString()

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(Diagnostic?, Diagnostic?)
operator !=(Diagnostic?, Diagnostic?)

operator ==(Diagnostic?, Diagnostic?)

public static bool operator ==(Diagnostic? left, Diagnostic? right)

Parameters

left Diagnostic?
right Diagnostic?

Returns

bool

No documentation is available.

operator !=(Diagnostic?, Diagnostic?)

public static bool operator !=(Diagnostic? left, Diagnostic? right)

Parameters

left Diagnostic?
right Diagnostic?

Returns

bool

No documentation is available.