Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a class during runtime

Is it possible to create a class during run-time and use it?

I am NOT referring to compiling code at run-time, generating a new assembly, loading it, executing it, etc. Reflection is a one-way street in that it can give you run-time info about your currently loaded assembly or one that you load from file or memory.

My question is more about injection I guess. Can you create a class at run-time within your own app domain and make it do anything useful?

like image 438
Raheel Khan Avatar asked May 01 '12 10:05

Raheel Khan


1 Answers

Is it possible to create a class during run-time and use it?

Yes, you could use Reflection.Emit. You may also checkout Castle.DynamicProxy which simplifies the process of manually generating the IL.

like image 113
Darin Dimitrov Avatar answered Sep 30 '22 08:09

Darin Dimitrov