Hello Rick,
Thank you for your reply. I would need a custom solution
just because dotnet framework does not support multiple
inheritance.
I actually need to intercept method calls, so change of
method definitions at runtime would also be a possible
solution for me. Do you know a good tool, or have some
source code for that?
Kemal
>-----Original Message-----
>Hi Kemal,
[quoted text clipped - 55 lines]
>
>.
"Rick Byers [MSFT]" - 07 Feb 2005 19:35 GMT
Right, the class you are proxying would have to extend MarshalByRefObject
(or ContextBoundObject) in order to use a TransparentProxy to intercept
calls to it. When the JIT compiler sees a non-virtual method call, it
needs to have the freedom to inline it which eliminates pretty much any
dynamic interception technique (MBROs are a special case). For your
original emitted-subclass approach do you require the user to use your
proxy type directly? If it is casted to the base class, interception of
non-vrituals no longer works. If that is acceptable for you, then perhaps
you could use encapsulation instead of inheritance.
The CLR has no general-purpose run-time interception mechanism (probably
due in large part to the performance implications). If this is what you
you're trying to achieve, you're probably out of luck. The only
possibility would be to use the profiler API to replace code on the fly
when it is jitted (see [1]). However, the profiler API is intended only to
be used in a development context, so depending on your exact scenario, it
is likely to be inappropriate.
Rick
[1] http://msdn.microsoft.com/msdnmag/issues/03/09/NETProfilingAPI/
--------
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
> From: "Kemal Erdogan" <kemal@erdogan.biz>
> Subject: RE: Calling a private base constructor from within a constructor
in MSIL
> Date: Sat, 5 Feb 2005 17:03:32 -0800
>
[quoted text clipped - 96 lines]
> >
> >.
Fabian Schmied - 08 Feb 2005 08:17 GMT
> I actually need to intercept method calls, so change of
> method definitions at runtime would also be a possible
> solution for me. Do you know a good tool, or have some
> source code for that?
I recently found Castle Project's DynamicProxy, which is more flexible
than the built-in proxy support, maybe you'll find it useful:
http://www.castleproject.org/castle/show/dynamicproxy
It works by creating dynamic proxy classes at runtime, either deriving
from your class and overriding virtual methods, or implementing an
interface and delegating to your own implementation. The first approach
has the disadvantage of supporting virtual methods only, but it also
allows interception of intra-object calls, which is a nice thing to have.
Fabian