Reputation: 8876
Is it possible to create a C# class (classname.cs
) file at runtime and then use the class at runtime.
If it is, then how can I implement this?
Upvotes: 4
Views: 5831
Reputation: 1989
Please look Generate C# Class Library project programatically with given fields. Not sure what means by runtime. But you can create many classes just clicking save (run t4 template).
Upvotes: 0
Reputation: 34391
Check out the classes in the namespace Microsoft.CSharp
. The CSharpCodeProvider
has a method CompileAssemblyFromSource
which can generate an in-memory assembly from your source.
Upvotes: 0
Reputation: 292385
Have a look at the CSharpCodeProvider class. There's a complete example on the MSDN page
Upvotes: 3