In the following, I need to pass nextDB to the Lambda expression in Retry:
Retry.Do(() => { string nextDB = dbList.Next(); using (DataBaseProxy repo = new DataBaseProxy(nextDB)) { return repo.DoSomething(); } }); How do I do that? Here is my Retry class:
public static class Retry { public static void Do( Action action, int retryCount = 3) { Do<object>(() => { action(); return null; }, retryCount); } public static T Do<T>( Func<T> action, int retryCount = 3) { var exceptions = new List<Exception>(); for (int retry = 0; retry < retryCount; retry++) { try { return action(); } catch (Exception ex) { exceptions.Add(ex); } } throw new AggregateException(exceptions); } }