SyntaxAnnotation Class

A marker that can be attached to a node, token, or trivia and found again after the tree has been edited.

public sealed class SyntaxAnnotation : IEquatable<SyntaxAnnotation?>

Remarks

Two annotations are equal only when they are the same annotation, even when their SyntaxAnnotation.Kind and SyntaxAnnotation.Data match. That is what makes "find the node I marked earlier" work: an edit rebuilds the nodes around the marked one, but carries its annotations forward, so the new tree can be searched for this exact instance.

Example

var root = XmlSyntaxTree.ParseText("<root><item>1</item></root>").GetRoot();
var node = root.DescendantNodes().OfType<XmlElementSyntax>().Single(element => element.Name == "item");

var marker = new SyntaxAnnotation();
var annotated = node.WithAdditionalAnnotations(marker);
var updated = root.ReplaceNode(node, annotated);
var found = updated.GetAnnotatedNodes(marker).Single();
Assert.Equal("<item>1</item>", found.ToFullString());
Implements

Constructors

NameDescription
SyntaxAnnotation()
SyntaxAnnotation(string?)
SyntaxAnnotation(string?, string?)

SyntaxAnnotation overloads

SyntaxAnnotation()

SyntaxAnnotation.cs
public SyntaxAnnotation()

No documentation is available.

SyntaxAnnotation(string?)

SyntaxAnnotation.cs
public SyntaxAnnotation(string? kind)
Parameters
kind string?

No documentation is available.

SyntaxAnnotation(string?, string?)

SyntaxAnnotation.cs
public SyntaxAnnotation(string? kind, string? data)
Parameters
kind string?
data string?

No documentation is available.

Properties

NameDescription
DataGets the payload carried alongside the annotation.
KindGets the category of the annotation, used to find annotations without holding the instance.

Gets the payload carried alongside the annotation.

public string? Data { get; }

Property value

string?

Gets the category of the annotation, used to find annotations without holding the instance.

public string? Kind { get; }

Property value

string?

Methods

NameDescription
Equals(SyntaxAnnotation?)
Equals(object?)
GetHashCode()
ToString()

Equals overloads

Equals(SyntaxAnnotation?)

SyntaxAnnotation.cs
public bool Equals(SyntaxAnnotation? other)
Parameters
other SyntaxAnnotation?
Returns

bool

No documentation is available.

Equals(object?)

SyntaxAnnotation.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

SyntaxAnnotation.cs
public override int GetHashCode()

Returns

int

No documentation is available.

public override string ToString()

Returns

string

No documentation is available.

Operators

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

operator ==(SyntaxAnnotation?, SyntaxAnnotation?)

SyntaxAnnotation.cs
public static bool operator ==(SyntaxAnnotation? left, SyntaxAnnotation? right)

Parameters

left SyntaxAnnotation?
right SyntaxAnnotation?

Returns

bool

No documentation is available.

operator !=(SyntaxAnnotation?, SyntaxAnnotation?)

SyntaxAnnotation.cs
public static bool operator !=(SyntaxAnnotation? left, SyntaxAnnotation? right)

Parameters

left SyntaxAnnotation?
right SyntaxAnnotation?

Returns

bool

No documentation is available.