namespace System { public static class ActionUtils { /// /// Action的安全回调 /// /// public static void SafeInvoke(this Action action) { try { action?.Invoke(); } catch (Exception ex) { XGame.Log.Exception(ex); } } /// /// Action的安全回调 /// /// /// /// public static void SafeInvoke(this Action action, T obj) { try { action?.Invoke(obj); } catch (Exception ex) { XGame.Log.Exception(ex); } } /// /// Action的安全回调 /// /// /// /// /// /// public static void SafeInvoke(this Action action, T argT, U argU) { try { action?.Invoke(argT, argU); } catch (Exception ex) { XGame.Log.Exception(ex); } } /// /// Action的安全回调 /// /// /// /// /// /// /// public static void SafeInvoke(this Action action, T argT, U argU, V argV) { try { action?.Invoke(argT, argU, argV); } catch (Exception ex) { XGame.Log.Exception(ex); } } /// /// Func的安全回调 /// /// /// /// public static TResult SafeInvoke(this Func func) { TResult result = default; try { if (func != null) result = func.Invoke(); } catch (Exception ex) { XGame.Log.Exception(ex); } return result; } /// /// Func的安全回调 /// /// /// /// /// /// public static TResult SafeInvoke(this Func func, T argT) { TResult result = default; try { if (func != null) result = func.Invoke(argT); } catch (Exception ex) { XGame.Log.Exception(ex); } return result; } } }