Created
September 6, 2015 11:02
-
-
Save angelovstanton/662359566b86a87f8ac3 to your computer and use it in GitHub Desktop.
This file contains 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
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