SHARE
TWEET

Untitled

ViIvanov Jan 24th, 2013 60 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.     EmitResult result;
  16.     using(var stream = new MemoryStream()) {
  17.       result = compilation.Emit(stream);
  18.     }//using
  19.  
  20.     var output = result.GetType()
  21.         .GetProperty("DebuggerDisplay", BindingFlags.Instance | BindingFlags.NonPublic)
  22.         .GetValue(result);
  23.     Console.WriteLine(output);
  24.   }
  25. }
RAW Paste Data
Top