tags:

views:

91

answers:

3

Is it possible to create a class at runtime from a file without parsing it?

If not what would be the best approach to retrieve class properties, constructors and methods from a file? Taking into account that a file could have more than one class just like a typical cs file.

+3  A: 

Yes, it's possible to create a class at runtime from a file.

Dynamic Source Code Generation and Compilation

Randolpho
ILGenerator FTW
darthtrevino
+1  A: 

You can use Runtime Compiler (Reflection) in MS.NET

Take a look here

Elalfer
A: 

If you are using ASP.NET take a look at BuildManager.GetCompiledAssembly.

Here's an example usage:

Assembly a = BuildManager.GetCompiledAssembly("~/TestClass.cs");
foreach (Type t in a.GetExportedTypes()) {
    object obj = Activator.CreateInstance(t)
    // Do something with obj...
}
Jason