How to create a class at runtime from a file

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

If this is not the best way to get class properties, constructors and methods from a file? Whereas a file can have more than one class, like a regular cs file.

+3
source share
3 answers

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

Dynamic source code generation and compilation

+4
source

You can use the Runtime (Reflection) compiler in MS.NET

Look here

+1
source

ASP.NET, BuildManager.GetCompiledAssembly.

:

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

Source: https://habr.com/ru/post/1723395/


All Articles