I donβt think there is a way to do this at runtime with reflection. What you probably want to do is use the AOP (aspect-oriented) approach, but this is also not supported by the .NET platform. You can use PostSharp if you don't mind using a compiler extension, or look at Unity2 to do AOP .
Edit: You can also consider Castle DynamicProxy . Or, if you have a clear understanding of DynamicMethods and IL code, you can create your own proxy generator class.
However, I think that in most cases you will have to properly encode the rest of your application for proxy processing. In other words, instead of executing:
Foo f = new Foo(); f.Property1 = 123;
You would need to do something like:
Foo f = Generator.GetProxy<Foo>(); // this code is fake. just indicates that you need to get an instance of Foo from a proxy generator, be it DynamicProxy or Unity or whatever. f.Property1 = 123;
source share