using DispenserCommon.Exceptions; namespace DispenserCommon.Utils; /// /// 断言工具类 /// public class AssertUtil { /// /// 判断条件是否为真 /// /// /// public static void IsTrue(bool expression, string msg) { if (!expression) { throw new AssertException(msg); } } /// /// 判断条件是否为假 /// /// /// public static void IsFalse(bool expression, string msg) { if (expression) { throw new AssertException(msg); } } /// /// 集合非空断言 /// /// /// public static void NotEmpty(List? list, string msg) { if (list == null || list.Count == 0) { throw new AssertException(msg); } } /// /// 集合空断言 /// /// /// public static void IsEmpty(List list, string msg) { if (list is { Count: > 0 }) { throw new AssertException(msg); } } /// /// 对象非空断言 /// /// /// /// public static void NotNull(object? model, string msg) { if (model == null) { throw new AssertException(msg); } } /// /// 对象空断言 /// /// /// /// public static void IsNull(object? model, string msg) { if (model != null) { throw new AssertException(msg); } } /// /// 字符串非空断言 /// /// /// /// public static void StringNotNullOrEmpty(string str, string msg) { if (string.IsNullOrEmpty(str)) { throw new AssertException(msg); } } }