I am curious to learn if .NET supports any form of dynamic interception of method calls (or properties invocations) at runtime. That is, can you intercept a call to an object without static compilation information such as an interface (along the lines of the CORBA DII (link text) or COM's IDispatch).
If not, would the new 'Dynamically Typed Objects' feature in C# 4.0 help in this regard.
There is nothing built-in that allows you to intercept an object that you can not control instantiation of. Similarly, there will be no new facilities for this in the upcoming .net 4.0.
If you can control instantiation:
If you can not control instantiation
Alternatively, you could look at a dynamic language like IronRuby, which has a built-in alias_method
and define_method
goodness (which allows you to redefine anything), so interception baked in.
In .NET 4.5, the aforementioned ICorProfiler
is introducing a method to ReJIT methods which provides another hook for method interception (provided you are not running a concurrent/bg GC and the method is not inlined).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With