Two possible answers:
- Use PostSharp. It costs, but I guess it works.
- You could use reflection to call the
PerformSetup
method before you call your methods
Basically you can make a base class with the following
class Base
{
public void InvokeMethodWithSetup(string method, Database db, params object[] args)
{
PerformSetup(db);
var method = this.GetType().GetMethod(method);
method.Invoke(this, args);
}
public void PerformSetup(Database db)
{
// stuff
}
}
This unfortunately means going to everywhere one of your methods is called to replace the invocation code, so I don't know if that makes it much easier, but at least it saves you having to modify all the methods.