Hi,
In our application, we acess a around many external data sources ranging
from sql to file shares. The code base is huge and been there for a while.
What I would like to achieve is:
Say, currently I call function foo once.
I would like to wrap this in a function say foowrap...which tries to invoke
the function x times before throwing up. Something like
void foo(){}
void foowrap()
{
for(int i=0;i<PolicyLimit;++i)
try
{
foo();
break;
}
catch(Exception e){}
}
The wrapper should be able to take any no of parameters and return the type
of the wrapped.
I have a working example, below
delegate void MyDelegate<T>(T a);
static class Robust<T>
{
public static void Invoke(MyDelegate<TmyDelegate, T param)
{
for (int i = 0; i < 10; ++i)
try
{
myDelegate(param);
break;
}
catch (Exception e){}
}
}
class Program
{
static void H(int k)
{
Console.WriteLine("Hello World");
}
static void Main(string[] args)
{
Robust<int>.Invoke(H, 7);
}
}
Please tell me, what would be the best way to go? AOP?
::Rajiv