Created
April 4, 2015 22:46
-
-
Save jmarolf/4b55afdd9a4c5269580c to your computer and use it in GitHub Desktop.
Get parse errors from string.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.CSharp; | |
using Microsoft.CodeAnalysis.Text; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var tree = CSharpSyntaxTree.ParseText(SourceText.From("class a{}")); | |
var compilation = CSharpCompilation.Create("test", new[] { tree }); | |
compilation = compilation.AddReferences( | |
MetadataReference.CreateFromAssembly(typeof(object).Assembly), | |
MetadataReference.CreateFromAssembly(typeof(IEnumerable).Assembly)); | |
var diagnostics = compilation.GetParseDiagnostics(); | |
foreach (var diagnostic in diagnostics) | |
{ | |
Console.WriteLine(diagnostic); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment