[Mono-list] How to do code injection with .NET
Paolo Molaro
lupus@ximian.com
Thu, 20 Feb 2003 18:47:37 +0100
On 02/20/03 Philippe Lavoie wrote:
> I've been reading a little about Aspect Oriented Design. And it seems
> objects inheriting from ContextBoundObject allow you to do that,
> although with some limitation, i.e. the framework only work with a
> context per class maximum (I couldn't find a way to have a new context
> for every method call inside the same class).
>
> I was wondering if I could do something like in J2EE, i.e.
>
> [Priviledge("EditProfile")]
> public void EditMethod(){
> ...
> }
>
> The above would in turn inject code inside the method that would be like
>
> public void EditMethod(){
> if(!
> ContextUtils.GetPriviledgeContext().HasPriviledge("EditProfile")){
> throw Security("Insufficient priviledge");
> }
> ...
> }
You can do something like that with Permissions, the msdn web site has
some info on it. If you want something more general you need to either
do some preprocessing (to the sources or to the generated IL code) or
use the profiling interface.
The profiling interface in mono doesn't let you do that, yet, though it
should not be hard to add.
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better