I tried using Roslyn to check the following example:
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);
The problem is that the GetDiagnostics () function cannot cut the error in Line Console.WriteLin * e * (....)
What am I doing wrong?
source share