Table of Contents

Class CsParser

Namespace
Alternet.Syntax.Parsers.Roslyn
Assembly
Alternet.Syntax.Parsers.Roslyn.v9.dll

Represents a class that performs syntax and lexical analysis of the specified C# code.

[ToolboxBitmap(typeof(RoslynParser), "Images.CsParser.Icon.bmp")]
public class CsParser : RoslynParser, IComponent, IDisposable, ISyntaxParser, IParser, ILexer, INotify, IUpdate, IImport
Inheritance
CsParser
Implements

Examples

Here is how to declare a CsParser and handle its events from the C# code:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        var parser = new Alternet.Syntax.Parsers.Roslyn.CsParser();
        var edit = new Alternet.Editor.SyntaxEdit();
        edit.Parent = this;
        edit.Lexer = parser;

        string fileName = "myfile.cs";
        if (System.IO.File.Exists(fileName))
        {
            parser.FileName = fileName;
            edit.LoadFile(fileName);
        }

        parser.TextReparsed += CsParser_TextReparsed;
    }

    private void CsParser_TextReparsed(object sender, EventArgs e)
    {
        var parser = sender as Alternet.Syntax.Parsers.Roslyn.CsParser;
        parser.FindReferences(new System.Drawing.Point(0, 0));
    }
}

Here is how to declare a CsParser and handle its events from the Visual Basic code:

Partial Public Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim parser = New Alternet.Syntax.Parsers.Roslyn.CsParser()
        Dim edit = New Alternet.Editor.SyntaxEdit()
        edit.Parent = Me
        edit.Lexer = parser
        Dim fileName As String = "myfile.cs"

        If System.IO.File.Exists(fileName) Then
            parser.FileName = fileName
            edit.LoadFile(fileName)
        End If

        AddHandler parser.TextReparsed, AddressOf Me.CsParser_TextReparsed
    End Sub

    Private Sub CsParser_TextReparsed(ByVal sender As Object, ByVal e As EventArgs)
        Dim parser = TryCast(sender, Alternet.Syntax.Parsers.Roslyn.CsParser)
        parser.FindReferences(New System.Drawing.Point(0, 0))
    End Sub
End Class

Remarks

CsParser is a non-visual component designed to perform syntax highlighting and provide advanced code editing capabilities for the C# language. This parser uses the Microsoft Code Analysis (Roslyn) API and performs full syntax and semantic analysis of the C# code, supporting up to C#10 language specification. When linked to the SyntaxEdit or TextEditor controls, this parser drives additional features such as code completion, code outlining, code formatting, highlighting types in different colors, and underlying syntax and semantic errors and warnings.

Here are some of the essential features provided by the CsParser:

  • Syntax Highlighting
  • IntelliSense (Code completion)
  • Signature Help (displaying parameter information for methods)
  • Code Outlining
  • Structure guidelines
  • Formatting a selected block of text or the whole document.
  • Finding declarations and references

Constructors

CsParser()

Initializes a new instance of the CsParser class with default settings.

CsParser(IRoslynSolution)

Initializes a new instance of the CsParser class with specified IRoslynSolution.

Methods

CreateRepository()

Creates ICodeCompletionRepository to perform code completion functionality for this parser.

GetCompletionType(char)

Obtains type of code completion window from specifies char parameter.

GetSingleLineComment()

Gets the string that represents start symbol of single line comment.

InitLanguage()
OutlineRegions(IList<IRange>, SpanResolver, SyntaxNode, int)
ResetAutoIndentChars()

Resets AutoIndentChars to the default value.

ResetCodeCompletionChars()

Resets CodeCompletionChars to the default value.

ResetSmartFormatChars()

Resets the SmartFormatChars to the default value.

ShouldSerializeAutoIndentChars()

Indicates whether the SmartFormatChars property should be persisted.

ShouldSerializeCodeCompletionChars()

Indicates whether the CodeCompletionChars property should be persisted.

ShouldSerializeSmartFormatChars()

Indicates whether the SmartFormatChars property should be persisted.