Skip to main content

SyntaxExtensions Class

Namespace: Roslynator.CSharp

Assembly: Roslynator.CSharp.dll

A set of extension methods for syntax (types derived from CSharpSyntaxNode).

public static class SyntaxExtensions

Methods

MethodSummary
Add(SyntaxList<StatementSyntax>, StatementSyntax, Boolean)Creates a new list with the specified node added or inserted.
AddUsings(CompilationUnitSyntax, Boolean, UsingDirectiveSyntax[])Creates a new CompilationUnitSyntax with the specified using directives added.
AsCascade(IfStatementSyntax)Returns IfStatementCascade that enables to enumerate if-else cascade.
AsChain(BinaryExpressionSyntax, TextSpan?)Returns ExpressionChain that enables to enumerate expressions of a binary expression.
BodyOrExpressionBody(AccessorDeclarationSyntax)Returns accessor body or an expression body if the body is null.
BodyOrExpressionBody(ConstructorDeclarationSyntax)Returns constructor body or an expression body if the body is null.
BodyOrExpressionBody(ConversionOperatorDeclarationSyntax)Returns conversion operator body or an expression body if the body is null.
BodyOrExpressionBody(DestructorDeclarationSyntax)Returns destructor body or an expression body if the body is null.
BodyOrExpressionBody(LocalFunctionStatementSyntax)Returns local function body or an expression body if the body is null.
BodyOrExpressionBody(MethodDeclarationSyntax)Returns method body or an expression body if the body is null.
BodyOrExpressionBody(OperatorDeclarationSyntax)Returns operator body or an expression body if the body is null.
BracesSpan(ClassDeclarationSyntax)The absolute span of the braces, not including its leading and trailing trivia.
BracesSpan(EnumDeclarationSyntax)The absolute span of the braces, not including its leading and trailing trivia.
BracesSpan(InterfaceDeclarationSyntax)The absolute span of the braces, not including it leading and trailing trivia.
BracesSpan(NamespaceDeclarationSyntax)The absolute span of the braces, not including leading and trailing trivia.
BracesSpan(RecordDeclarationSyntax)The absolute span of the braces, not including its leading and trailing trivia.
BracesSpan(StructDeclarationSyntax)The absolute span of the braces, not including its leading and trailing trivia.
Contains(SyntaxTokenList, SyntaxKind)Returns true if a token of the specified kind is in the SyntaxTokenList.
Contains(SyntaxTriviaList, SyntaxKind)Returns true if a trivia of the specified kind is in the SyntaxTriviaList.
Contains<TNode>(SeparatedSyntaxList<TNode>, SyntaxKind)Searches for a node of the specified kind and returns the zero-based index of the first occurrence within the entire SeparatedSyntaxList<TNode>.
Contains<TNode>(SyntaxList<TNode>, SyntaxKind)Returns true if a node of the specified kind is in the SyntaxList<TNode>.
ContainsAny(SyntaxTokenList, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token of the specified kinds is in the SyntaxTokenList.
ContainsAny(SyntaxTokenList, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token of the specified kinds is in the SyntaxTokenList.
ContainsAny(SyntaxTokenList, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token of the specified kinds is in the SyntaxTokenList.
ContainsAny(SyntaxTokenList, SyntaxKind, SyntaxKind)Returns true if a token of the specified kinds is in the SyntaxTokenList.
ContainsDefaultLabel(SwitchSectionSyntax)Returns true if the specified switch section contains default switch label.
ContainsUnbalancedIfElseDirectives(SyntaxNode, TextSpan)Returns true if the specified node contains #if directive but it does not contain related #endif directive.
ContainsUnbalancedIfElseDirectives(SyntaxNode)Returns true if the specified node contains #if directive but it does not contain related #endif directive.
ContainsYield(LocalFunctionStatementSyntax)Returns true if the specified local function contains yield statement. Nested local functions are excluded.
ContainsYield(MethodDeclarationSyntax)Returns true if the specified method contains yield statement. Nested local functions are excluded.
DeclarationOrExpression(UsingStatementSyntax)Returns using statement's declaration or an expression if the declaration is null.
DefaultSection(SwitchStatementSyntax)Returns a section that contains default label, or null if the specified switch statement does not contains section with default label.
Elements(DocumentationCommentTriviaSyntax, String)Gets a list of xml elements with the specified local name.
Find(SyntaxTokenList, SyntaxKind)Searches for a token of the specified kind and returns the first occurrence within the entire SyntaxTokenList.
Find(SyntaxTriviaList, SyntaxKind)Searches for a trivia of the specified kind and returns the first occurrence within the entire SyntaxList<TNode>.
Find<TNode>(SeparatedSyntaxList<TNode>, SyntaxKind)Searches for a node of the specified kind and returns the first occurrence within the entire SeparatedSyntaxList<TNode>.
Find<TNode>(SyntaxList<TNode>, SyntaxKind)Searches for a node of the specified kind and returns the first occurrence within the entire SyntaxList<TNode>.
FirstAncestor(SyntaxNode, Func<SyntaxNode, Boolean>, Boolean)Gets the first ancestor that matches the predicate.
FirstAncestor(SyntaxNode, SyntaxKind, Boolean)Gets the first ancestor of the specified kind.
FirstAncestor(SyntaxNode, SyntaxKind, SyntaxKind, Boolean)Gets the first ancestor of the specified kinds.
FirstAncestor(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, Boolean)Gets the first ancestor of the specified kinds.
FirstAncestorOrSelf(SyntaxNode, Func<SyntaxNode, Boolean>, Boolean)Gets the first ancestor that matches the predicate.
FirstAncestorOrSelf(SyntaxNode, SyntaxKind, Boolean)Gets the first ancestor of the specified kind.
FirstAncestorOrSelf(SyntaxNode, SyntaxKind, SyntaxKind, Boolean)Gets the first ancestor of the specified kinds.
FirstAncestorOrSelf(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, Boolean)Gets the first ancestor of the specified kinds.
GetCascadeInfo(IfStatementSyntax)Returns IfStatementCascadeInfo that summarizes information about if-else cascade.
GetDocumentationComment(MemberDeclarationSyntax)Returns documentation comment syntax that is part of the specified declaration.
GetDocumentationCommentTrivia(MemberDeclarationSyntax)Returns documentation comment that is part of the specified declaration.
GetEndRegionDirective(RegionDirectiveTriviaSyntax)Returns endregion directive that is related to the specified region directive. Returns null if no matching endregion directive is found.
GetFirstDirective(SyntaxNode, TextSpan, Func<DirectiveTriviaSyntax, Boolean>)Gets the first directive of the tree rooted by this node.
GetNextRelatedDirective(DirectiveTriviaSyntax)Returns the next related directive.
GetPreprocessingMessageTrivia(EndRegionDirectiveTriviaSyntax)Gets preprocessing message for the specified endregion directive if such message exists.
GetPreprocessingMessageTrivia(RegionDirectiveTriviaSyntax)Gets preprocessing message for the specified region directive if such message exists.
GetRegionDirective(EndRegionDirectiveTriviaSyntax)Returns region directive that is related to the specified endregion directive. Returns null if no matching region directive is found.
GetSingleLineDocumentationComment(MemberDeclarationSyntax)Returns single-line documentation comment syntax that is part of the specified declaration.
GetSingleLineDocumentationCommentTrivia(MemberDeclarationSyntax)Returns single-line documentation comment that is part of the specified declaration.
Getter(AccessorListSyntax)Returns a get accessor contained in the specified list.
Getter(IndexerDeclarationSyntax)Returns a get accessor that is contained in the specified indexer declaration.
Getter(PropertyDeclarationSyntax)Returns property get accessor, if any.
GetTopmostIf(ElseClauseSyntax)Returns topmost if statement of the if-else cascade the specified else clause is part of.
GetTopmostIf(IfStatementSyntax)Returns topmost if statement of the if-else cascade the specified if statement is part of.
HasDocumentationComment(MemberDeclarationSyntax)Returns true if the specified declaration has a documentation comment.
HasSingleLineDocumentationComment(MemberDeclarationSyntax)Returns true if the specified declaration has a single-line documentation comment.
IsAutoImplemented(AccessorDeclarationSyntax)Returns true is the specified accessor is auto-implemented accessor.
IsDescendantOf(SyntaxNode, SyntaxKind, Boolean)Returns true if a node is a descendant of a node with the specified kind.
IsEmbedded(StatementSyntax, Boolean, Boolean, Boolean)Returns true if the specified statement is an embedded statement.
IsEmptyOrWhitespace(SyntaxTriviaList)Returns true if the list of either empty or contains only whitespace (SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia).
IsEndOfLineTrivia(SyntaxTrivia)Returns true if the trivia is SyntaxKind.EndOfLineTrivia.
IsHexNumericLiteral(LiteralExpressionSyntax)Returns true if the specified literal expression is a hexadecimal numeric literal expression.
IsInExpressionTree(SyntaxNode, SemanticModel, CancellationToken)Determines if the specified node is contained in an expression tree.
IsKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node's kind is one of the specified kinds.
IsKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node's kind is one of the specified kinds.
IsKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node's kind is one of the specified kinds.
IsKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node's kind is one of the specified kinds.
IsKind(SyntaxNode, SyntaxKind, SyntaxKind)Returns true if a node's kind is one of the specified kinds.
IsKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxToken, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxTrivia, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxTrivia, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxTrivia, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxTrivia, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token's kind is one of the specified kinds.
IsKind(SyntaxTrivia, SyntaxKind, SyntaxKind)Returns true if a trivia's kind is one of the specified kinds.
IsLast(SyntaxList<StatementSyntax>, StatementSyntax, Boolean)Returns true if the specified statement is a last statement in the list.
IsParams(ParameterSyntax)Returns true if the specified parameter has "params" modifier.
IsParentKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node parent's kind is one of the specified kinds.
IsParentKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node parent's kind is one of the specified kinds.
IsParentKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node parent's kind is one of the specified kinds.
IsParentKind(SyntaxNode, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a node parent's kind is one of the specified kinds.
IsParentKind(SyntaxNode, SyntaxKind, SyntaxKind)Returns true if a node parent's kind is one of the specified kinds.
IsParentKind(SyntaxNode, SyntaxKind)Returns true if a node parent's kind is the specified kind.
IsParentKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token parent's kind is one of the specified kinds.
IsParentKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token parent's kind is one of the specified kinds.
IsParentKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token parent's kind is one of the specified kinds.
IsParentKind(SyntaxToken, SyntaxKind, SyntaxKind, SyntaxKind)Returns true if a token parent's kind is one of the specified kinds.
IsParentKind(SyntaxToken, SyntaxKind, SyntaxKind)Returns true if a token parent's kind is one of the specified kinds.
IsParentKind(SyntaxToken, SyntaxKind)Returns true if a token parent's kind is the specified kind.
IsSimpleIf(IfStatementSyntax)Returns true if the specified if statement is a simple if statement. Simple if statement is defined as follows: it is not a child of an else clause and it has no else clause.
IsTopmostIf(IfStatementSyntax)Returns true if the specified if statement is not a child of an else clause.
IsVerbatim(InterpolatedStringExpressionSyntax)Returns true if the specified interpolated string is a verbatim.
IsVoid(TypeSyntax)Returns true if the type is Void.
IsWhitespaceOrEndOfLineTrivia(SyntaxTrivia)Returns true if the trivia is either SyntaxKind.WhitespaceTrivia or SyntaxKind.EndOfLineTrivia.
IsWhitespaceTrivia(SyntaxTrivia)Returns true if the trivia is SyntaxKind.WhitespaceTrivia.
IsYieldBreak(YieldStatementSyntax)Returns true if the specified statement is a yield break statement.
IsYieldReturn(YieldStatementSyntax)Returns true if the specified statement is a yield return statement.
LastIndexOf(SyntaxTriviaList, SyntaxKind)Searches for a trivia of the specified kind and returns the zero-based index of the last occurrence within the entire SyntaxTriviaList.
LastIndexOf<TNode>(SeparatedSyntaxList<TNode>, SyntaxKind)Searches for a node of the specified kind and returns the zero-based index of the last occurrence within the entire SeparatedSyntaxList<TNode>.
LastIndexOf<TNode>(SyntaxList<TNode>, SyntaxKind)Searches for a node of the specified kind and returns the zero-based index of the last occurrence within the entire SyntaxList<TNode>.
NextStatement(StatementSyntax)Gets the next statement of the specified statement. If the specified statement is not contained in the list, or if there is no next statement, then this method returns null.
ParenthesesSpan(CastExpressionSyntax)The absolute span of the parentheses, not including its leading and trailing trivia.
ParenthesesSpan(CommonForEachStatementSyntax)The absolute span of the parentheses, not including its leading and trailing trivia.
ParenthesesSpan(ForStatementSyntax)Absolute span of the parentheses, not including the leading and trailing trivia.
PreviousStatement(StatementSyntax)Gets the previous statement of the specified statement. If the specified statement is not contained in the list, or if there is no previous statement, then this method returns null.
RemoveRange(SyntaxTokenList, Int32, Int32)Creates a new list with tokens in the specified range removed.
RemoveRange(SyntaxTriviaList, Int32, Int32)Creates a new list with trivia in the specified range removed.
RemoveRange<TNode>(SeparatedSyntaxList<TNode>, Int32, Int32)Creates a new list with elements in the specified range removed.
RemoveRange<TNode>(SyntaxList<TNode>, Int32, Int32)Creates a new list with elements in the specified range removed.
RemoveTrivia<TNode>(TNode, TextSpan?)Creates a new node with the trivia removed.
RemoveWhitespace<TNode>(TNode, TextSpan?)Creates a new node with the whitespace removed.
ReplaceRange(SyntaxTokenList, Int32, Int32, IEnumerable<SyntaxToken>)Creates a new list with the tokens in the specified range replaced with new tokens.
ReplaceRange(SyntaxTriviaList, Int32, Int32, IEnumerable<SyntaxTrivia>)Creates a new list with the trivia in the specified range replaced with new trivia.
ReplaceRange<TNode>(SeparatedSyntaxList<TNode>, Int32, Int32, IEnumerable<TNode>)Creates a new list with the elements in the specified range replaced with new nodes.
ReplaceRange<TNode>(SeparatedSyntaxList<TNode>, Int32, Int32, TNode)Creates a new list with the elements in the specified range replaced with new node.
ReplaceRange<TNode>(SyntaxList<TNode>, Int32, Int32, IEnumerable<TNode>)Creates a new list with the elements in the specified range replaced with new nodes.
ReplaceRange<TNode>(SyntaxList<TNode>, Int32, Int32, TNode)Creates a new list with the elements in the specified range replaced with new node.
ReplaceWhitespace<TNode>(TNode, SyntaxTrivia, TextSpan?)Creates a new node with the whitespace replaced.
ReturnsVoid(DelegateDeclarationSyntax)Returns true the specified delegate return type is Void.
ReturnsVoid(LocalFunctionStatementSyntax)Returns true if the specified local function' return type is Void.
ReturnsVoid(MethodDeclarationSyntax)Returns true if the specified method return type is Void.
Setter(AccessorListSyntax)Returns a set accessor contained in the specified list.
Setter(IndexerDeclarationSyntax)Returns a set accessor that is contained in the specified indexer declaration.
Setter(PropertyDeclarationSyntax)Returns property set accessor, if any.
ToSeparatedSyntaxList<TNode>(IEnumerable<SyntaxNodeOrToken>)Creates a separated list of syntax nodes from a sequence of nodes and tokens.
ToSeparatedSyntaxList<TNode>(IEnumerable<TNode>)Creates a separated list of syntax nodes from a sequence of nodes.
ToSyntaxList<TNode>(IEnumerable<TNode>)Creates a list of syntax nodes from a sequence of nodes.
ToSyntaxTokenList(IEnumerable<SyntaxToken>)Creates a list of syntax tokens from a sequence of tokens.
TrimLeadingTrivia(SyntaxToken)Removes all leading whitespace from the leading trivia and returns a new token with the new leading trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same token if there is nothing to trim.
TrimLeadingTrivia<TNode>(TNode)Removes all leading whitespace from the leading trivia and returns a new node with the new leading trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same node if there is nothing to trim.
TrimTrailingTrivia(SyntaxToken)Removes all trailing whitespace from the trailing trivia and returns a new token with the new trailing trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same token if there is nothing to trim.
TrimTrailingTrivia<TNode>(TNode)Removes all trailing whitespace from the trailing trivia and returns a new node with the new trailing trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same node if there is nothing to trim.
TrimTrivia(SyntaxToken)Removes all leading whitespace from the leading trivia and all trailing whitespace from the trailing trivia and returns a new token with the new trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same token if there is nothing to trim.
TrimTrivia<TNode>(SeparatedSyntaxList<TNode>)Removes all leading whitespace from the leading trivia of the first node in a list and all trailing whitespace from the trailing trivia of the last node in a list and returns a new list with the new trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace.
TrimTrivia<TNode>(SyntaxList<TNode>)Removes all leading whitespace from the leading trivia of the first node in a list and all trailing whitespace from the trailing trivia of the last node in a list and returns a new list with the new trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace.
TrimTrivia<TNode>(TNode)Removes all leading whitespace from the leading trivia and all trailing whitespace from the trailing trivia and returns a new node with the new trivia. SyntaxKind.WhitespaceTrivia and SyntaxKind.EndOfLineTrivia is considered to be a whitespace. Returns the same node if there is nothing to trim.
TryGetContainingList(StatementSyntax, SyntaxList<StatementSyntax>)Gets a list the specified statement is contained in. This method succeeds if the statement is in a block's statements or a switch section's statements.
WalkDownParentheses(ExpressionSyntax)Returns lowest expression in parentheses or self if the expression is not parenthesized.
WalkUpParentheses(ExpressionSyntax)Returns topmost parenthesized expression or self if the expression if not parenthesized.
WithMembers(ClassDeclarationSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new ClassDeclarationSyntax with the members updated.
WithMembers(ClassDeclarationSyntax, MemberDeclarationSyntax)Creates a new ClassDeclarationSyntax with the members updated.
WithMembers(CompilationUnitSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new CompilationUnitSyntax with the members updated.
WithMembers(CompilationUnitSyntax, MemberDeclarationSyntax)Creates a new CompilationUnitSyntax with the members updated.
WithMembers(InterfaceDeclarationSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new InterfaceDeclarationSyntax with the members updated.
WithMembers(InterfaceDeclarationSyntax, MemberDeclarationSyntax)Creates a new InterfaceDeclarationSyntax with the members updated.
WithMembers(NamespaceDeclarationSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new NamespaceDeclarationSyntax with the members updated.
WithMembers(NamespaceDeclarationSyntax, MemberDeclarationSyntax)Creates a new NamespaceDeclarationSyntax with the members updated.
WithMembers(RecordDeclarationSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new RecordDeclarationSyntax with the members updated.
WithMembers(RecordDeclarationSyntax, MemberDeclarationSyntax)Creates a new RecordDeclarationSyntax with the members updated.
WithMembers(StructDeclarationSyntax, IEnumerable<MemberDeclarationSyntax>)Creates a new StructDeclarationSyntax with the members updated.
WithMembers(StructDeclarationSyntax, MemberDeclarationSyntax)Creates a new StructDeclarationSyntax with the members updated.