It is possible to add proxy capabilities to an already generated and not empty object using Castle Dynamic Proxy?
I’ve tried this:
Dog _myDog=new Dog();
_myDog.Name="Fuffy";
var _proxyDog = generator.CreateClassProxyWithTarget<Dog>(_myDog, ProxyGenerationOptions.Default, new DogInterceptor());
_proxyDog results as a new object.
Now this is only an example, in real world application my object has 30+ properties and I want to know if I can avoid to copy those props one by one!
Yes it is. The only problem: ProxyGenerator needs to instantiate an object of that type anyway. This code is actually working correctly in my project:
Paramerts of CreateClassProxyWithTarget are:
I can’t really explain, why it need constructor parameters for the object, but this code work correctly for me.