XmlSyntaxRewriter Class
Builds a new tree by visiting an old one and returning replacements.
public class XmlSyntaxRewriter : XmlSyntaxVisitor<SyntaxNode?>Remarks
A node whose parts all come back unchanged is returned as it was, so rewriting a tree and changing nothing in it costs nothing and keeps every node.
Example
private sealed class RenameRoot : XmlSyntaxRewriter
{
public override SyntaxNode? VisitElement(XmlElementSyntax node)
=> node.Name == "root" ? node.WithName("renamed") : base.VisitElement(node);
}- Inheritance
XmlSyntaxVisitor<SyntaxNode?>XmlSyntaxRewriter
Constructors
| Name | Description |
|---|---|
| XmlSyntaxRewriter() |
XmlSyntaxRewriter()
public XmlSyntaxRewriter()No documentation is available.
Methods
VisitAttribute(XmlAttributeSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitAttribute(XmlAttributeSyntax node)No documentation is available.
VisitCDataSection(XmlCDataSectionSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitCDataSection(XmlCDataSectionSyntax node)No documentation is available.
VisitComment(XmlCommentSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitComment(XmlCommentSyntax node)No documentation is available.
VisitDeclaration(XmlDeclarationSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitDeclaration(XmlDeclarationSyntax node)No documentation is available.
VisitDocument(XmlDocumentSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitDocument(XmlDocumentSyntax node)No documentation is available.
VisitDocumentType(XmlDocumentTypeSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitDocumentType(XmlDocumentTypeSyntax node)No documentation is available.
VisitElement(XmlElementSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitElement(XmlElementSyntax node)No documentation is available.
VisitElementEndTag(XmlElementEndTagSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitElementEndTag(XmlElementEndTagSyntax node)No documentation is available.
VisitElementStartTag(XmlElementStartTagSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitElementStartTag(XmlElementStartTagSyntax node)No documentation is available.
VisitEmptyElement(XmlEmptyElementSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitEmptyElement(XmlEmptyElementSyntax node)No documentation is available.
VisitList overloads
VisitList(SyntaxTokenList)
XmlSyntaxRewriter.cspublic virtual SyntaxTokenList VisitList(SyntaxTokenList list)No documentation is available.
VisitList(SyntaxTriviaList)
XmlSyntaxRewriter.csRewrites each trivium of a list, dropping the ones a rewrite turned into the default trivium.
public virtual SyntaxTriviaList VisitList(SyntaxTriviaList list)VisitList<TNode>(SyntaxList<TNode>)
XmlSyntaxRewriter.cspublic virtual SyntaxList<TNode> VisitList<TNode>(SyntaxList<TNode> list) where TNode : XmlSyntaxNodeNo documentation is available.
VisitProcessingInstruction(XmlProcessingInstructionSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitProcessingInstruction(XmlProcessingInstructionSyntax node)No documentation is available.
VisitSkippedText(XmlSkippedTextSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitSkippedText(XmlSkippedTextSyntax node)No documentation is available.
VisitText(XmlTextSyntax)
XmlSyntaxRewriter.cspublic override SyntaxNode? VisitText(XmlTextSyntax node)No documentation is available.
VisitToken(SyntaxToken)
XmlSyntaxRewriter.csRewrites a token, putting the trivia around it through XmlSyntaxRewriter.VisitTrivia.
public virtual SyntaxToken VisitToken(SyntaxToken token)Parameters
tokenSyntaxToken
Returns
Remarks
Nothing else reaches a token's trivia, so an override of XmlSyntaxRewriter.VisitTrivia would never be called if this returned the token untouched. A rewrite that returns the default trivium removes it.
VisitTrivia(SyntaxTrivia)
XmlSyntaxRewriter.cspublic virtual SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)No documentation is available.