Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created September 6, 2015 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/662359566b86a87f8ac3 to your computer and use it in GitHub Desktop.
Save angelovstanton/662359566b86a87f8ac3 to your computer and use it in GitHub Desktop.
public static void Main(string[] args)
{
var sourceCode = @"class HelloKittyPrinter
{
public void Print()
{
System.Console.WriteLine(""Hello Hello Kitty!"");
}
}";
var compiledAssembly = CompileSourceCodeDom(sourceCode);
ExecuteFromAssembly(compiledAssembly);
}
private static Assembly CompileSourceCodeDom(string sourceCode)
{
CodeDomProvider csharpCodeProvider = new CSharpCodeProvider();
var cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.dll");
cp.GenerateExecutable = false;
CompilerResults cr = csharpCodeProvider.CompileAssemblyFromSource(cp, sourceCode);
return cr.CompiledAssembly;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment