Answer Dynamic Code Generation

I was just wondering if it was possible to take a string that contains C# code and compile and use it at runtime. For example if I had a string like this:

String strCode = @" class SomeClass : SomeBaseClass {

private string firstName;
private string lastName;

public SomeClass() {

this.firstName = ""John"";
this.lastName = ""Smith"";

}

... Properties ...

}" ;

I have been reading about the CSharpCodeProvider class, however it doesn't look like you can just compile a string containing code.




Answer this question

Answer Dynamic Code Generation