Good things need to be sorted and classified
Note: The namespace is required SyntacticSugar
usage:
/***Extended function name***/ //【IsInRange】 int num = 100; //Previous writingif (num > 100 & num < 1000) { } //Writing nowif ((100, 1000)) { } //Datetime type also supports //【IsNullOrEmpty】 object s = ""; //Previous writingif (s == null || (())) { } //Writing nowif (()) { } //It's easier to do it } //【IsIn】 string value = "a"; //I have seen the writing style in many projects beforeif (value == "a" || value == "b" || value == "c") { } //Writing nowif (("a", "b", "c")) { } //【IsValuable is the opposite of IsNullOrEmpty】string ss = ""; //Previous writingif (!(ss)) { } //Writing nowif (()) { } List<string> list = null; //Previous writingif (list != null && > 0) { } //Writing nowif (()) { } //IsIDcard if ("32061119810104311x".IsIDcard()) { } //IsTelephone if ("0513-85669884".IsTelephone()) { } //IsMatch saves you the namespace that references Regexif ("I Chinese 12".IsMatch(@"people\d{2}")) { } //There are many things that are too simple to introduce below.//IsZero //IsInt //IsNoInt //IsMoney //IsEamil //IsMobile
Source code:
using System; using ; using ; using ; using ; namespace SyntacticSugar { /// <summary> /// ** Description: What is a logical judgment segment? /// ** Founding time: 2015-5-29 /// ** Modification time:- /// ** Author: sunkaixuan /// </summary> public static class IsWhat { /// <summary> /// The range of values? /// </summary> /// <param name="o"></param> /// <param name="begin">greater than or equal to begin</param> /// <param name="end">less than or equal to end</param> /// <returns></returns> public static bool IsInRange(this int o, int begin, int end) { return o >= begin && o <= end; } /// <summary> /// The range of values? /// </summary> /// <param name="o"></param> /// <param name="begin">greater than or equal to begin</param> /// <param name="end">less than or equal to end</param> /// <returns></returns> public static bool IsInRange(this DateTime o, DateTime begin, DateTime end) { return o >= begin && o <= end; } /// <summary> /// Inside? /// </summary> /// <typeparam name="T"></typeparam> /// <param name="o"></param> /// <param name="values"></param> /// <returns></returns> public static bool IsIn<T>(this T o, params T[] values) { return (o); } /// <summary> /// Is it null or ""? /// </summary> /// <returns></returns> public static bool IsNullOrEmpty(this object o) { if (o == null || o == ) return true; return () == ""; } /// <summary> /// Is it null or ""? /// </summary> /// <returns></returns> public static bool IsNullOrEmpty(this Guid? o) { if (o == null) return true; return o == ; } /// <summary> /// Is it null or ""? /// </summary> /// <returns></returns> public static bool IsNullOrEmpty(this Guid o) { if (o == null) return true; return o == ; } /// <summary> /// Is there a value? (Contrary to IsNullOrEmpty) /// </summary> /// <returns></returns> public static bool IsValuable(this object o) { if (o == null) return false; return () != ""; } /// <summary> /// Is there a value? (Contrary to IsNullOrEmpty) /// </summary> /// <returns></returns> public static bool IsValuable(this IEnumerable<object> o) { if (o == null || () == 0) return false; return true; } /// <summary> /// Is it zero? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsZero(this object o) { return (o == null || () == "0"); } /// <summary> /// Is it INT? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsInt(this object o) { if (o == null) return false; return ((), @"^\d+$"); } /// <summary> /// Not INT? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsNoInt(this object o) { if (o == null) return true; return !((), @"^\d+$"); } /// <summary> /// Is it money? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsMoney(this object o) { if (o == null) return false; double outValue = 0; return ((), out outValue); } /// <summary> /// Is it the email? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsEamil(this object o) { if (o == null) return false; return ((), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$"); } /// <summary> /// Is it a cell phone? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsMobile(this object o) { if (o == null) return false; return ((), @"^\d{11}$"); } /// <summary> /// Is it a landline? /// </summary> public static bool IsTelephone(this object o) { if (o == null) return false; return ((), @"^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}$"); } /// <summary> /// Is it an ID card? /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool IsIDcard(this object o) { if (o == null) return false; return ((), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$"); } /// <summary> ///Is it suitable for regular matching? /// </summary> /// <param name="o"></param> /// <param name="begin">greater than or equal to begin</param> /// <param name="end">less than or equal to end</param> /// <returns></returns> public static bool IsMatch(this object o, string pattern) { if (o == null) return false; Regex reg = new Regex(pattern); return (()); } } }