I had asked this question before, but I didn't do a very good job explaining so here I go again...
I have a class something like this
public class BaseClass {
public void Setup() { Do something... }
public void TearDown() { Do something else...}
{
public class SubClass : BaseClass {
public Object1 Method1(Object2 o2) {
Setup();
Do something specific to this method...
TearDown();
return object1;
}
public Object3 Method2(Object4 o4, Object5 o5) {
Setup();
Do something different here...
TearDown();
return object3;
}
}
There are other classes that extend BaseClass and the methods in those classes also have to run Setup and TearDown in a similar way.
What I would like to do is not have to call the Setup and TearDown for every method I create. I would like to simply do something like this:
public class BaseClass {
[RunBeforeEveryMethod]
public void Setup() { Do something... }
[RunAfterEveryMethod]
public void TearDown() { Do something else...}
{
public class SubClass : BaseClass {
public Object1 Method1(Object2 o2) {
Do something specific to this method...
return object1;
}
public Object3 Method2(Object4 o4, Object5 o5) {
Do something different here...
return object3;
}
}
I've seen other posts like this and this that are similar. But my situation is a bit different because:
- I have to call a method both before and after.
- I also have multiple methods with different method names in the sub class where every method has to call these setup and teardown.
- The parameters can be anything and any number.