Allan,
The only way you are going to be able to do this is through
ContextBoundObjects. It's a little-known feature of .NET which allows you
to intercept method calls and perform pre and post processing.
The feature itself is not documented, but I believe MS says that they
will not change it, or remove support for it either.
There is a detailed explaination of it (as a matter of fact, a whole
chapter) in Juval Lowy's book, "Programming .NET Components", 2nd edition.
You can find the book at Amazon (watch for line wrap):
http://www.amazon.com/exec/obidos/tg...books&n=507846
He also wrote an artile on it for MSDN magazine. You can find that here
(watch for line wrap):
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
These should help. I think you can intercept property get/sets, but
they are channeled to the sink as a call to the get_<property>,
set_<property> methods.
Also, you can intercept construction calls as well with this
architecture.
The biggest caveat here is that you are remoting, in a sense, so there
is going to be some overhead while going through the sink chain.
If you are thinking of doing something like parameter validation, you
have to seriously weigh this option out, because the performance hit you are
going to get compared to calling a function or performing a check in the
beginning of your method is going to be significant.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Allan Ebdrup" <co****@ofir.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
Is it possible to listen to when a constructor is called or when a
property is set on a object, without having to implement changes in the
observed objects class, in dotNet 2.0? It would be very effective for
implementing a Model View Control architecture.
Perhaps some stuff could be generated runtime using reflection?
Kind Regards,
Allan Ebdrup