using JNPF.DependencyInjection; namespace JNPF.Common.Extension; /// /// 布尔值类型的扩展辅助操作类. /// [SuppressSniffer] public static class BooleanExtensions { /// /// 把布尔值转换为小写字符串. /// /// public static string ToLower(this bool value) { return value.ToString().ToLower(); } /// /// 如果条件成立,则抛出异常. /// public static void TrueThrow(this bool flag, Exception exception) { if (flag) throw exception; } /// /// 获取布尔值. /// private static bool? GetBool(this object data) { switch (data.ToString()?.Trim().ToLower()) { case "0": return false; case "1": return true; case "是": return true; case "否": return false; case "yes": return true; case "no": return false; default: return null; } } }