Table of Contents

Property Repository

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

Repository

Gets an IRoslynRepository that holds methods for code completion purposes.

[Browsable(false)]
public IRoslynRepository Repository { get; }

Property Value

IRoslynRepository

Examples

Here is how to use a Repository in 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;
        var document = parser.Repository.Document;
        if (document != null)
        {
            var text = document.GetTextAsync().Result;
        }
    }
}

Here is how to use a Repository in 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)
        Dim document = parser.Repository.Document

        If document IsNot Nothing Then
            Dim text = document.GetTextAsync().Result
        End If
    End Sub
End Class

Remarks

Use Repository property to get access to the Roslyn-specific properties like Document.