Invokation added at runtime?

Y

Ympostor

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.

--
 
J

Jon Skeet [C# MVP]

Ympostor said:
I have an abstract class with a bool property:

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top