Table of Contents

Property ProjectName

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

ProjectName

Gets or sets a string specifying the name of the project to which the given code corresponds.

[Browsable(false)]
public string ProjectName { get; set; }

Property Value

string

Examples

Here is how to use a ProjectName 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";
        var projectName = "TestProject.csproj";
        if (System.IO.File.Exists(fileName))
        {
            parser.FileName = fileName;
            edit.LoadFile(fileName);
            parser.ProjectName = projectName;
        }

        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 ProjectName 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"
        Dim projectName = "TestProject.csproj"

        If System.IO.File.Exists(fileName) Then
            parser.FileName = fileName
            edit.LoadFile(fileName)
            parser.ProjectName = projectName
        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 the ProjectName property to associate the code parsed by the RoslynParser object with the specific project.