AssertBool.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using XGame.Framework.Assertions;
  2. using System.Diagnostics;
  3. namespace XGame.Framework
  4. {
  5. public static partial class Assert
  6. {
  7. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  8. public static void IsTrue(bool condition)
  9. {
  10. if (!condition)
  11. IsTrue(condition, null);
  12. }
  13. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  14. public static void IsTrue(bool condition, string format, params object[] agrs)
  15. {
  16. if (!condition)
  17. Fail(AssertionMessageUtil.BooleanFailureMessage(true), format, agrs);
  18. }
  19. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  20. public static void IsTrue<T>(bool condition, T e) where T : System.Exception, new()
  21. {
  22. if (!condition)
  23. Fail(AssertionMessageUtil.BooleanFailureMessage(true), e);
  24. }
  25. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  26. public static void IsFalse(bool condition)
  27. {
  28. if (condition)
  29. IsFalse(condition, null);
  30. }
  31. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  32. public static void IsFalse(bool condition, string format, params object[] agrs)
  33. {
  34. if (condition)
  35. Fail(AssertionMessageUtil.BooleanFailureMessage(false), format, agrs);
  36. }
  37. [Conditional(MacroDefine.XGAME_ASSERT), Conditional(MacroDefine.UNITY_EDITOR)]
  38. public static void IsFalse<T>(bool condition, T e) where T : System.Exception, new()
  39. {
  40. if (condition)
  41. Fail(AssertionMessageUtil.BooleanFailureMessage(false), e);
  42. }
  43. }
  44. }