2

Is it possible to create a dynamic proxy using common libraries like Castle Dynamic Proxy without having any base class or interface? I'm indeed interested to have dynamic on-the-fly classes in run-time.

Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126

1 Answers1

3

Sure, use Reflection.Emit to bake your interface, then pass the generated interface type to CreateInterfaceProxyWithoutTarget and provide interceptors.

Just keep in mind that you cannot unload a type, only an appdomain, so if you are going to create thousands of types you might end-up in a world of hurt performance-wise.

Florian Doyon
  • 4,146
  • 1
  • 27
  • 37