| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 | using System;using System.Collections.Generic;using System.Linq;using System.Text.RegularExpressions;namespace SqlSugar.BzTDengineCore{    internal static class ValidateExtensions    {        public static bool IsInRange(this int thisValue, int begin, int end)        {            return thisValue >= begin && thisValue <= end;        }        public static bool IsInRange(this DateTime thisValue, DateTime begin, DateTime end)        {            return thisValue >= begin && thisValue <= end;        }        public static bool IsIn<T>(this T thisValue, params T[] values)        {            return values.Contains(thisValue);        }        public static bool IsContainsIn(this string thisValue, params string[] inValues)        {            return inValues.Any(it => thisValue.Contains(it));        }        public static bool IsNullOrEmpty(this object thisValue)        {            if (thisValue == null || thisValue == DBNull.Value) return true;            return thisValue.ToString() == "";        }        public static bool IsNullOrEmpty(this Guid? thisValue)        {            if (thisValue == null) return true;            return thisValue == Guid.Empty;        }        public static bool IsNullOrEmpty(this Guid thisValue)        {            if (thisValue == null) return true;            return thisValue == Guid.Empty;        }        public static bool IsNullOrEmpty(this IEnumerable<object> thisValue)        {            if (thisValue == null || thisValue.Count() == 0) return true;            return false;        }        public static bool HasValue(this object thisValue)        {            if (thisValue == null || thisValue == DBNull.Value) return false;            return thisValue.ToString() != "";        }        public static bool HasValue(this IEnumerable<object> thisValue)        {            if (thisValue == null || thisValue.Count() == 0) return false;            return true;        }        public static bool IsValuable(this IEnumerable<KeyValuePair<string, string>> thisValue)        {            if (thisValue == null || thisValue.Count() == 0) return false;            return true;        }        public static bool IsZero(this object thisValue)        {            return (thisValue == null || thisValue.ToString() == "0");        }        public static bool IsInt(this object thisValue)        {            if (thisValue == null) return false;            return Regex.IsMatch(thisValue.ToString(), @"^\d+$");        }        /// <returns></returns>        public static bool IsNoInt(this object thisValue)        {            if (thisValue == null) return true;            return !Regex.IsMatch(thisValue.ToString(), @"^\d+$");        }        public static bool IsMoney(this object thisValue)        {            if (thisValue == null) return false;            double outValue = 0;            return double.TryParse(thisValue.ToString(), out outValue);        }        public static bool IsGuid(this object thisValue)        {            if (thisValue == null) return false;            Guid outValue = Guid.Empty;            return Guid.TryParse(thisValue.ToString(), out outValue);        }        public static bool IsDate(this object thisValue)        {            if (thisValue == null) return false;            DateTime outValue = DateTime.MinValue;            return DateTime.TryParse(thisValue.ToString(), out outValue);        }        public static bool IsEamil(this object thisValue)        {            if (thisValue == null) return false;            return Regex.IsMatch(thisValue.ToString(), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");        }        public static bool IsMobile(this object thisValue)        {            if (thisValue == null) return false;            return Regex.IsMatch(thisValue.ToString(), @"^\d{11}$");        }        public static bool IsTelephone(this object thisValue)        {            if (thisValue == null) return false;            return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}$");        }        public static bool IsIDcard(this object thisValue)        {            if (thisValue == null) return false;            return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$");        }        public static bool IsFax(this object thisValue)        {            if (thisValue == null) return false;            return System.Text.RegularExpressions.Regex.IsMatch(thisValue.ToString(), @"^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$");        }        public static bool IsMatch(this object thisValue, string pattern)        {            if (thisValue == null) return false;            Regex reg = new Regex(pattern);            return reg.IsMatch(thisValue.ToString());        }        public static bool IsAnonymousType(this Type type)        {            string typeName = type.Name;            return typeName.Contains("<>") && typeName.Contains("__") && typeName.Contains("AnonymousType");        }        public static bool IsCollectionsList(this string thisValue)        {            return (thisValue + "").StartsWith("System.Collections.Generic.List") || (thisValue + "").StartsWith("System.Collections.Generic.IEnumerable");        }        public static bool IsStringArray(this string thisValue)        {            return (thisValue + "").IsMatch(@"System\.[a-z,A-Z,0-9]+?\[\]");        }        public static bool IsEnumerable(this string thisValue)        {            return (thisValue + "").StartsWith("System.Linq.Enumerable");        }        public static Type StringType = typeof(string);        public static bool IsClass(this Type thisValue)        {            return thisValue != StringType && thisValue.IsEntity() && thisValue != UtilConstants.ByteArrayType;        }    }}
 |