में लिनेनंबर दिया गया है, मैं स्थान (lineNumber) को दी गई रेखा के सिंटेक्स नोड प्राप्त करना चाहता हूं। नीचे दिया गया कोड आत्म-स्पष्टीकरण होना चाहिए, लेकिन मुझे किसी भी प्रश्न के बारे में बताएं।सिंटैक्स नोड को सिंटेक्सट्री
static void Main()
{
string codeSnippet = @"using System;
class Program
{
static void Main(string[] args)
{
Console.WriteLine(""Hello, World!"");
}
}";
SyntaxTree tree = SyntaxTree.ParseCompilationUnit(codeSnippet);
string[] lines = codeSnippet.Split('\n');
SyntaxNode node = GetNode(tree, 6); //How??
}
static SyntaxNode GetNode(SyntaxTree tree,int lineNumber)
{
throw new NotImplementedException();
// *** What I did ***
//Calculted length from using System... to Main(string[] args) and named it (totalSpan)
//Calculated length of the line(lineNumber) Console.Writeline("Helllo...."); and named it (lineSpan)
//Created a textspan : TextSpan span = new TextSpan(totalSpan, lineSpan);
//Was able to get back the text of the line : tree.GetLocation(span);
//But how to get the SyntaxNode corresponding to that line??
}
क्या होगा यदि उस रेखा पर कोई नोड न हो? यदि एक से अधिक है तो क्या होगा? – svick
@svick मैं आदर्श मामला मान रहा हूं। –