AssertNull.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using XGame.Framework.Assertions;
  2. using System.Diagnostics;
  3. namespace XGame.Framework
  4. {
  5. public static partial class Assert
  6. {
  7. //public static void IsNull<T>(T value) where T : class
  8. //{
  9. // IsNull(value, null);
  10. //}
  11. //public static void IsNull<T>(T value, string format, params object[] args) where T : class
  12. //{
  13. // if (typeof(object).IsAssignableFrom(typeof(T)))
  14. // {
  15. // IsNull(value as object, format, args);
  16. // }
  17. // else if (value != null)
  18. // {
  19. // Fail(AssertionMessageUtil.NullFailureMessage(value, true), format, args);
  20. // }
  21. //}
  22. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  23. public static void IsNull(object value, string format, params object[] args)
  24. {
  25. if (value != null)
  26. Fail(AssertionMessageUtil.NullFailureMessage(value, true), format, args);
  27. }
  28. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  29. public static void IsNull<T>(object value, T e) where T : System.Exception
  30. {
  31. if (value != null)
  32. Fail(AssertionMessageUtil.NullFailureMessage(value, true), e);
  33. }
  34. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  35. public static void IsNotNull(object value)
  36. {
  37. IsNotNull(value, null);
  38. }
  39. //public static void IsNotNull<T>(T value) where T : class
  40. //{
  41. // IsNotNull(value, null);
  42. //}
  43. //public static void IsNotNull<T>(T value, string format, params object[] args) where T : class
  44. //{
  45. // if (typeof(object).IsAssignableFrom(typeof(T)))
  46. // {
  47. // IsNotNull(value as object, format, args);
  48. // }
  49. // else if (value == null)
  50. // {
  51. // Fail(AssertionMessageUtil.NullFailureMessage(value, false), format, args);
  52. // }
  53. //}
  54. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  55. public static void IsNotNull(object value, string format, params object[] args)
  56. {
  57. if (value == null)
  58. Fail(AssertionMessageUtil.NullFailureMessage(value, false), format, args);
  59. }
  60. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  61. public static void IsNotNull<T>(object value, T e) where T : System.Exception
  62. {
  63. if (value == null)
  64. Fail(AssertionMessageUtil.NullFailureMessage(value, false), e);
  65. }
  66. }
  67. }