Ejemplo n.º 1
0
 public SafeCallResult <T> SafeCall <T>(Func <T> action, IEnumerable <Type> exceptions)
 {
     try
     {
         T result = action == null ? default(T) : action.Invoke();
         return(SafeCallResult <T> .CreateSuccess(result));
     }
     catch (Exception e)
     {
         if (exceptions == null || exceptions.Any(t => t.IsAssignableFrom(e.GetType())))
         {
             return(SafeCallResult <T> .CreateError(e));
         }
         throw;
     }
 }
Ejemplo n.º 2
0
 public SafeCallResult SafeCall(Action action, IEnumerable <Type> exceptions)
 {
     try
     {
         action?.Invoke();
         return(SafeCallResult.CreateSuccess());
     }
     catch (Exception e)
     {
         if (exceptions == null || exceptions.Any(t => t.IsAssignableFrom(e.GetType())))
         {
             return(SafeCallResult.CreateError(e));
         }
         throw;
     }
 }