Created
September 16, 2019 05:52
-
-
Save jetstreamin/ae843e3e0513ce74a440337be25af6af to your computer and use it in GitHub Desktop.
Created with Copy to Gist
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
//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