Table of Contents

Class RoslynParser

Namespace
SunamoRoslyn
Assembly
SunamoRoslyn.dll

Parses C# code using Roslyn syntax tree classes. RoslynParserText handles text/indexer-based parsing without Roslyn classes.

public class RoslynParser
Inheritance
RoslynParser
Inherited Members
Extension Methods

Methods

GetAccessModifiers(SyntaxTokenList)

Gets the access modifier keyword from a list of syntax tokens.

public static string GetAccessModifiers(SyntaxTokenList modifiers)

Parameters

modifiers SyntaxTokenList

The list of modifier tokens to search.

Returns

string

The access modifier text, or empty string if none found.

GetCodeOfElementsClass(string, string)

Extracts code elements from classes in ASPX code-behind files and writes them to a target folder. Reads comments inside for implementation details.

public Task<List<string>?> GetCodeOfElementsClass(string folderFrom, string folderTo)

Parameters

folderFrom string

The source folder containing ASPX code-behind files.

folderTo string

The destination folder for output files.

Returns

Task<List<string>>

Always returns null; files are written to the destination folder.

GetVariablesInCsharp(CompilationUnitSyntax, out List<string>)

Extracts variable declarations from a C# compilation unit. The first argument must be CompilationUnitSyntax because global usings are only available on that type.

public static ABCRoslyn GetVariablesInCsharp(CompilationUnitSyntax root, out List<string> usings)

Parameters

root CompilationUnitSyntax

The compilation unit syntax root to extract variables from.

usings List<string>

Output list of using directives found in the compilation unit.

Returns

ABCRoslyn

A collection of variable type-name pairs found in the class.

GetVariablesInEveryMethod(string)

Gets all variables used in every method within the given source code.

public static Dictionary<string, List<string>> GetVariablesInEveryMethod(string text)

Parameters

text string

The C# source code text to analyze.

Returns

Dictionary<string, List<string>>

A dictionary mapping method names to their assigned variable names.

IsCSharpCode(string)

Determines whether the given input string is valid C# code.

public static bool IsCSharpCode(string input)

Parameters

input string

The source code text to validate.

Returns

bool

True if the input can be parsed as C# code; otherwise, false.

Method(string)

Parses a method header string into a MethodDeclarationSyntax.

public static MethodDeclarationSyntax Method(string methodHeader)

Parameters

methodHeader string

The method header text to parse (body will be appended automatically).

Returns

MethodDeclarationSyntax

The parsed method declaration syntax node.

ParseVariables(object)

Parses declared and assigned variables from a code fragment.

public static Tuple<List<string>, List<string>> ParseVariables(object code)

Parameters

code object

The code to parse; can be a string or a SyntaxNode.

Returns

Tuple<List<string>, List<string>>

A tuple of (declaredVariables, assignedVariables) lists.

SyntaxNodeFromObjectOrString(object)

Creates a SyntaxNode from either a string of code or an existing SyntaxNode.

public static SyntaxNode SyntaxNodeFromObjectOrString(object code)

Parameters

code object

The code to convert; can be a string or a SyntaxNode.

Returns

SyntaxNode

The resulting syntax node.