Himadri
Himadri

Reputation: 8876

How to generate a C# class file from C# code behind?

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

Answers (3)

Mahesh Malpani
Mahesh Malpani

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

erikkallen
erikkallen

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

Thomas Levesque
Thomas Levesque

Reputation: 292385

Have a look at the CSharpCodeProvider class. There's a complete example on the MSDN page

Upvotes: 3

Related Questions