Skip to content

Instantly share code, notes, and snippets.

@jetstreamin
Created September 16, 2019 05:52
Show Gist options
  • Save jetstreamin/ae843e3e0513ce74a440337be25af6af to your computer and use it in GitHub Desktop.
Save jetstreamin/ae843e3e0513ce74a440337be25af6af to your computer and use it in GitHub Desktop.
Created with Copy to Gist
//https://www.youtube.com/watch?v=dY6jR52fFWo
using System.CodeDom.Compiler;
using Microsoft.CSharp;
public class CompilerTest {
public object RunCode (string userCode) {
CSharpCodeProvider provider = new CSharpCodeProvider ();
CompilerResults results = provider.CompileAssemblyFromSource (new CompileParameters (), userCode);
System.Type classType = results.CompiledAssembly.GetType("MyClass");
System.Reflection.MethodInfo method = classType.GetMethod("MyMethod");
return method.Invoke (null, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment