I have an abstract class with a bool property:
class Abstract {
protected bool throwException;
protected void ThrowException{
if (this.throwException){
throw new MyException();
}
}
}
I then have two derived classes that have propertys:
class A : Abstract {
property X {
get { ... }
set { ... }
}
property Y {
get { ... }
set { ... }
}
}
class B : Abstract {
property Z {
get { ... }
set { ... }
}
}
How can I implement an scenario where the objects from class A or from
class B invoke the abstract method ThrowException every time a property
is accessed I mean, inserting the call as the first instruction of the
get/set methods, without having to coding it, just inserting the call at
runtime (modifying the accessors at runtime)?
Thanks in advance.
--
Truong Hong Thi - 23 Nov 2006 11:30 GMT
You may checkout some AOP (Aspect Oriented Programming) containers,
like http://www.springframework.net
Thi
http://thith.blogspot.com
> I have an abstract class with a bool property:
>
[quoted text clipped - 38 lines]
>
> --
Jon Skeet [C# MVP] - 23 Nov 2006 14:31 GMT
> I have an abstract class with a bool property:
<snip>
> How can I implement an scenario where the objects from class A or from
> class B invoke the abstract method ThrowException every time a property
> is accessed I mean, inserting the call as the first instruction of the
> get/set methods, without having to coding it, just inserting the call at
> runtime (modifying the accessors at runtime)?
It sounds like you're after Aspect-Oriented Programming (AOP). I
haven't done any of that on .NET (and only a bit in Java) but you may
well find some useful articles and libraries online. I would guess that
most are likely to intercept assembly loading and weave the extra calls
in at that point.
Jon