Table of Contents

Class ChildNodes

Namespace
SunamoRoslyn
Assembly
SunamoRoslyn.dll

Provides methods for retrieving child and descendant syntax nodes from a Roslyn syntax tree.

public class ChildNodes
Inheritance
ChildNodes
Inherited Members
Extension Methods

Methods

Class(SyntaxNode)

Returns the class declaration from a syntax node.

public static ClassDeclarationSyntax? Class(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to extract the class from.

Returns

ClassDeclarationSyntax

The class declaration syntax node, or null if not found.

FieldsDescendant(SyntaxNode)

Returns all descendant field declarations.

public static IList<FieldDeclarationSyntax> FieldsDescendant(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to search for descendant field declarations.

Returns

IList<FieldDeclarationSyntax>

A list of descendant field declaration syntax nodes.

Method(ClassDeclarationSyntax, string)

Finds a method declaration within a class by its header text.

public static MethodDeclarationSyntax? Method(ClassDeclarationSyntax classDeclaration, string methodHeader)

Parameters

classDeclaration ClassDeclarationSyntax

The class declaration to search within.

methodHeader string

The method header text to find.

Returns

MethodDeclarationSyntax

The matching method declaration syntax node.

Methods(SyntaxNode)

Returns direct child method declarations. If not working, try MethodsDescendant(SyntaxNode).

public static IList<MethodDeclarationSyntax> Methods(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to search for method declarations.

Returns

IList<MethodDeclarationSyntax>

A list of method declaration syntax nodes.

MethodsDescendant(SyntaxNode)

Returns all descendant method declarations. If not working, try Methods(SyntaxNode).

public static IList<MethodDeclarationSyntax> MethodsDescendant(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to search for descendant method declarations.

Returns

IList<MethodDeclarationSyntax>

A list of descendant method declaration syntax nodes.

Namespace(SyntaxNode)

Returns the namespace declaration from a syntax node.

public static NamespaceDeclarationSyntax? Namespace(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to extract the namespace from.

Returns

NamespaceDeclarationSyntax

The namespace declaration syntax node, or null if not found.

NamespaceOrClass(SyntaxNode)

Returns the first namespace or class declaration from a root syntax node.

public static SyntaxNode? NamespaceOrClass(SyntaxNode root)

Parameters

root SyntaxNode

The root syntax node to search.

Returns

SyntaxNode

The namespace or class declaration syntax node.

VariablesDescendant(SyntaxNode)

Returns all descendant variable declarations. VariablesDescendant returns only the variable part (e.g. int a1). FieldsDescendant returns the whole field declaration (e.g. public int a1).

public static IList<VariableDeclarationSyntax> VariablesDescendant(SyntaxNode syntaxNode)

Parameters

syntaxNode SyntaxNode

The syntax node to search for descendant variable declarations.

Returns

IList<VariableDeclarationSyntax>

A list of descendant variable declaration syntax nodes.