Created
June 11, 2012 11:01
-
-
Save DinisCruz/2909592 to your computer and use it in GitHub Desktop.
O2 Script to use Roslyn to Dynamically compile and execute a method (Simpler version)
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
panel.clear().add_ConsoleOut(); | |
var code = @" | |
using System; | |
class Greeter | |
{ | |
static string Greet() | |
{ | |
Console.WriteLine(""Hello, World!!!""); | |
return ""Another hello""; | |
} | |
}"; | |
return code.tree() // parse code and create SytaxtTree | |
.compiler() // create compiler | |
.create_Assembly() // compile code and create in memory assembly (of OutputKind.DynamicallyLinkedLibrary) | |
.type("Greeter") // use reflection to get type 'Greeter' | |
.invokeStatic("Greet"); // use reflection to get and invoke method Greet | |
//O2Ref:O2_FluentSharp_Roslyn.dll | |
//O2File:API_ConsoleOut.cs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment