J
John Rivers
Sometimes an overriding method needs to call the base method at the
beginning:
override void Blah() {
base.Blah();
// do stuff
}//method
sometimes at the end:
override void Blah() {
// do stuff
base.Blah();
}//method
sometimes in the middle:
override void Blah() {
// do stuff
base.Blah();
// do more stuff
}//method
but sometimes you need to insert the overriding code in the middle of
the base function:
(or split the base method code in two)
abstract void Blah();
void BlahEntry() {
// do stuff
Blah(); // virtual
// do more stuff
}//method
then sometimes you would like to reverse the order or intercept the
virtual calls:
(I am just making up syntax to show the point)
abstract void Blah();
intercept void Blah() {
Log("blah called");
}//method
or even
intercept entry void Blah() {
Log("blah entry");
}//method
intercept exit void Blah() {
Log("blah exit");
}//method
the reason for the post is that as I develop applications I find that
achieving the above
with csharp is not straightforward - especially when you are a few
levels down the hierarchy
and cannot change certain base classes
is this a common feeling or am I missing some tricks?
beginning:
override void Blah() {
base.Blah();
// do stuff
}//method
sometimes at the end:
override void Blah() {
// do stuff
base.Blah();
}//method
sometimes in the middle:
override void Blah() {
// do stuff
base.Blah();
// do more stuff
}//method
but sometimes you need to insert the overriding code in the middle of
the base function:
(or split the base method code in two)
abstract void Blah();
void BlahEntry() {
// do stuff
Blah(); // virtual
// do more stuff
}//method
then sometimes you would like to reverse the order or intercept the
virtual calls:
(I am just making up syntax to show the point)
abstract void Blah();
intercept void Blah() {
Log("blah called");
}//method
or even
intercept entry void Blah() {
Log("blah entry");
}//method
intercept exit void Blah() {
Log("blah exit");
}//method
the reason for the post is that as I develop applications I find that
achieving the above
with csharp is not straightforward - especially when you are a few
levels down the hierarchy
and cannot change certain base classes
is this a common feeling or am I missing some tricks?