ActionUtils.cs 917 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace System
  2. {
  3. public static class ActionUtils
  4. {
  5. /// <summary>
  6. /// ActionµÄ°²È«»Øµ÷
  7. /// </summary>
  8. /// <param name="action"></param>
  9. public static void SafeInvoke(this Action action)
  10. {
  11. try
  12. {
  13. action?.Invoke();
  14. }
  15. catch (Exception ex)
  16. {
  17. XGame.Log.Exception(ex);
  18. }
  19. }
  20. /// <summary>
  21. /// ActionµÄ°²È«»Øµ÷
  22. /// </summary>
  23. /// <typeparam name="T"></typeparam>
  24. /// <param name="action"></param>
  25. /// <param name="obj"></param>
  26. public static void SafeInvoke<T>(this Action<T> action, T obj)
  27. {
  28. try
  29. {
  30. action?.Invoke(obj);
  31. }
  32. catch (Exception ex)
  33. {
  34. XGame.Log.Exception(ex);
  35. }
  36. }
  37. }
  38. }