我尝试使用 Roslyn 检查以下示例:
static void Main(string[] args)
{
string sScriptCsx = @"
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLin(""Hello, World!"");
}
}
}";
string strDetail = "";
Diagnostic obj;
SyntaxTree stTree = SyntaxTree.ParseText(sScriptCsx);
if (stTree.GetDiagnostics().Count == 0)
{
strDetail += "La génération a réussi. Aucune erreur détectée.";
Environment.Exit(0);
}
for (int i = 0; i < stTree.GetDiagnostics().Count; i++)
{
obj = stTree.GetDiagnostics()[i];
strDetail += "<b>" + (i + 1).ToString() + ". Info: </b>" + obj.Info.ToString() + Environment.NewLine;
strDetail += " <b>Warning Level: </b>" + obj.Info.WarningLevel.ToString() + Environment.NewLine;
strDetail += " <b>Severity Level: </b>" + obj.Info.Severity.ToString() + Environment.NewLine;
strDetail += " <b>Location: </b>" + obj.Location.Kind.ToString() + Environment.NewLine;
strDetail += " <b>Character at: </b>" + obj.Location.GetLineSpan(true).StartLinePosition.Character.ToString() + Environment.NewLine;
strDetail += " <b>On Line: </b>" + obj.Location.GetLineSpan(true).StartLinePosition.Line.ToString() + Environment.NewLine;
strDetail += Environment.NewLine;
}
Console.WriteLine(strDetail);
问题是 GetDiagnostics() 函数无法检测 Line Console.WriteLin* e *(....)上的错误
我究竟做错了什么?