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
modifiersSyntaxTokenListThe 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
folderFromstringThe source folder containing ASPX code-behind files.
folderTostringThe destination folder for output files.
Returns
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
rootCompilationUnitSyntaxThe compilation unit syntax root to extract variables from.
usingsList<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
textstringThe 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
inputstringThe 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
methodHeaderstringThe 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
codeobjectThe code to parse; can be a string or a SyntaxNode.
Returns
SyntaxNodeFromObjectOrString(object)
Creates a SyntaxNode from either a string of code or an existing SyntaxNode.
public static SyntaxNode SyntaxNodeFromObjectOrString(object code)
Parameters
codeobjectThe code to convert; can be a string or a SyntaxNode.
Returns
- SyntaxNode
The resulting syntax node.