Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Castle DynamicProxy to initialize a constructor with parameters

How to use Castle DynamicProxy to initialize a constructor with parameters? In this case MyClass(int).

public class MyClass
{
   public MyClass(){}
   public MyClass(int p1){}
}

Currently, CreateClassProxy() initializes MyClass().

like image 501
Babak Avatar asked Sep 22 '13 08:09

Babak


1 Answers

CreateClassProxy has a lot of overloads. Including one where you pass parameters in an object array. This should work for you:

generator.CreateClassProxy(typeof(MyClass), new object[] { (int)2 });

Here is the official signature:

public object CreateClassProxy(Type classToProxy, object[] constructorArguments, params IInterceptor[] interceptors);

like image 151
meilke Avatar answered Sep 19 '22 17:09

meilke