Advertisement
ViIvanov

Untitled

Jan 25th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4. using Roslyn.Compilers;
  5. using Roslyn.Compilers.CSharp;
  6.  
  7. internal static class Program
  8. {
  9.   private static void Main() {
  10.     var text = @"enum E { A } class P { const E E = E.A; static void Main() { } }";
  11.     var tree = SyntaxTree.ParseText(text);
  12.     var mscorlib = MetadataReference.CreateAssemblyReference("mscorlib");
  13.     var options = new CompilationOptions(OutputKind.ConsoleApplication);
  14.     var compilation = Compilation.Create("X", options, new[] { tree, }, new[] { mscorlib, });
  15.     var result = compilation.Emit(Stream.Null);
  16.     var output = result.GetType()
  17.         .GetProperty("DebuggerDisplay", BindingFlags.Instance | BindingFlags.NonPublic)
  18.         .GetValue(result);
  19.     Console.WriteLine(output);
  20.   }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement