Created
September 22, 2012 00:38
-
-
Save ElemarJR/3764678 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Roslyn.Compilers; | |
| using Roslyn.Scripting.CSharp; | |
| using Roslyn.Scripting; | |
| namespace Roslyn_CTP2012 | |
| { | |
| static class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Action<object> print = Console.WriteLine; | |
| var session = CreateSession(); | |
| print("Roslyn REPL for C#"); | |
| while (true) | |
| { | |
| Console.Write(">"); | |
| try | |
| { | |
| print(session.Execute(Console.ReadLine())); | |
| } | |
| catch (Exception e) | |
| { | |
| print(e); | |
| } | |
| } | |
| } | |
| static Session CreateSession() | |
| { | |
| return new ScriptEngine() | |
| .CreateSession() | |
| .AddAssemblyReference("System") | |
| .AddAssemblyReference("System.Core") | |
| .AddAssemblyReference("System.Data") | |
| .AddAssemblyReference("System.Data.DataSetExtensions"); | |
| } | |
| static Session AddAssemblyReference( | |
| this Session session, | |
| string assemblyName | |
| ) | |
| { | |
| var reference = MetadataReference | |
| .CreateAssemblyReference(assemblyName); | |
| session | |
| .AddReference(reference); | |
| return session; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment