Table of Contents

Property FileName

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

FileName

Gets or sets file name of the file being parsed.

public override string FileName { get; set; }

Property Value

string

Examples

Here is how to use a FileName 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;
        parser.FindReferences(new System.Drawing.Point(0, 0));
    }
}

Here is how to use a FileName 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)
        parser.FindReferences(New System.Drawing.Point(0, 0))
    End Sub
End Class

Remarks

Use FileName property to associate RoslynParser object with the file's name after loading text from it.