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
| Name | Description |
|---|---|
| SyntaxAnnotation() | |
| SyntaxAnnotation(string?) | |
| SyntaxAnnotation(string?, string?) |
SyntaxAnnotation overloads
SyntaxAnnotation()
SyntaxAnnotation.cspublic SyntaxAnnotation()No documentation is available.
SyntaxAnnotation(string?)
SyntaxAnnotation.csSyntaxAnnotation(string?, string?)
SyntaxAnnotation.csProperties
| Name | Description |
|---|---|
| Data | Gets the payload carried alongside the annotation. |
| Kind | Gets the category of the annotation, used to find annotations without holding the instance. |
Methods
| Name | Description |
|---|---|
| Equals(SyntaxAnnotation?) | |
| Equals(object?) | |
| GetHashCode() | |
| ToString() |
Equals overloads
Equals(SyntaxAnnotation?)
SyntaxAnnotation.cspublic bool Equals(SyntaxAnnotation? other)No documentation is available.
Equals(object?)
SyntaxAnnotation.csGetHashCode()
SyntaxAnnotation.csToString()
SyntaxAnnotation.csOperators
| Name | Description |
|---|---|
| operator ==(SyntaxAnnotation?, SyntaxAnnotation?) | |
| operator !=(SyntaxAnnotation?, SyntaxAnnotation?) |
operator ==(SyntaxAnnotation?, SyntaxAnnotation?)
SyntaxAnnotation.cspublic static bool operator ==(SyntaxAnnotation? left, SyntaxAnnotation? right)No documentation is available.
operator !=(SyntaxAnnotation?, SyntaxAnnotation?)
SyntaxAnnotation.cspublic static bool operator !=(SyntaxAnnotation? left, SyntaxAnnotation? right)No documentation is available.