Bobben,
Basically, you are looking for something like Aspect Oriented
Programming. While AOP offers you other ways to weave aspects, the basic
mechanism that you are looking for is method interception. .NET does offer
something like this, using Context-bound objects. However, there is a price
to pay for it.
A good article to read on this is on MSDN, titled "Decouple Components
by Injecting Custom Services into Your Object's Interception Chain", located
at (watch for line wrap):
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
It will show you how to do exactly what you want.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"bobben" <bo****@nospam.com> wrote in message
news:uw**************@TK2MSFTNGP11.phx.gbl...
Hi everybody.
I don't know if this is possible, but I am looking for a way to
automatically inject code.
I would like to fire a Debug.Writeline() automatically when a method is
invoked and when the method exists.
Anybody knows if this is at all possible? Or is any other variant possible
?
Is custom attributes a way to go?
Basically I want a similar behaviour as ServicedComponent class with its
[Autocomplete] attribute:
It does one thing if all goes well and another thing if exceptions occurs?
Any ideas anybody...
thank anyway!
Bobben