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; } }
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; } }