Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
Created June 11, 2012 11:01
Show Gist options
  • Save DinisCruz/2909592 to your computer and use it in GitHub Desktop.
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)
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