好东西都需要人去整理、分类
注意:需要引用命名空间 SyntacticSugar
用法:
//【IsInRange】
int num = 100;
//以前写法
if (num > 100 & num < 1000) { }
//现在写法
if (num.IsInRange(100, 1000)) { } //datetime类型也支持
//【IsNullOrEmpty】
object s = "";
//以前写法
if (s == null || string.IsNullOrEmpty(s.ToString())) { }
//现在写法
if (s.IsNullOrEmpty()) { }
//更顺手了没有 }
//【IsIn】
string value = "a";
//以前写法我在很多项目中看到
if (value == "a" || value == "b" || value == "c") {
}
//现在写法
if (value.IsIn("a", "b", "c")) {
}
//【IsValuable与IsNullOrEmpty相反】
string ss = "";
//以前写法
if (!string.IsNullOrEmpty(ss)) { }
//现在写法
if (s.IsValuable()) { }
List list = null;
//以前写法
if (list != null && list.Count > 0) { }
//现在写法
if (list.IsValuable()) { }
//IsIDcard
if ("32061119810104311x".IsIDcard())
{
}
//IsTelephone
if ("0513-85669884".IsTelephone())
{
}
//IsMatch 节约你引用Regex的命名空间了
if ("我中国人12".IsMatch(@"人d{2}")) { }
//下面还有很多太简单了的就不介绍了
//IsZero
//IsInt
//IsNoInt
//IsMoney
//IsEamil
//IsMobile
源码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Regularexpressions;
namespace SyntacticSugar
{
///
/// ** 描述:逻辑判段是什么?
/// ** 创始时间:2015-5-29
/// ** 修改时间:-
/// ** 作者:sunkaixuan
///
public static class IsWhat
{
///
/// 值在的范围?
///
///
/// 大于等于begin
/// 小于等于end
///
public static bool IsInRange(this int o, int begin, int end)
{
return o >= begin && o <= end;
}
///
/// 值在的范围?
///
///
/// 大于等于begin
/// 小于等于end
///
public static bool IsInRange(this DateTime o, DateTime begin, DateTime end)
{
return o >= begin && o <= end;
}
///
/// 在里面吗?
///
///
///
///
///
public static bool IsIn(this T o, params T[] values)
{
return values.Contains(o);
}
///
/// 是null或""?
///
///
public static bool IsNullOrEmpty(this object o)
{
if (o == null || o == DBNull.Value) return true;
return o.ToString() == "";
}
///
/// 是null或""?
///
///
public static bool IsNullOrEmpty(this Guid? o)
{
if (o == null) return true;
return o == Guid.Empty;
}
///
/// 是null或""?
///
///
public static bool IsNullOrEmpty(this Guid o)
{
if (o == null) return true;
return o == Guid.Empty;
}
///
/// 有值?(与IsNullOrEmpty相反)
///
///
public static bool IsValuable(this object o)
{
if (o == null) return false;
return o.ToString() != "";
}
///
/// 有值?(与IsNullOrEmpty相反)
///
///
public static bool IsValuable(this IEnumerable



