SoFunction
Updated on 2025-03-07

C#, general tool class IsWhat? (You can judge numbers, ID cards, data types, etc.)

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>    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsInRange(this int o, int begin, int end)
    {
      return o &gt;= begin &amp;&amp; o &lt;= end;
    }
    /// &lt;summary&gt;
    /// The range of values?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// <param name="begin">greater than or equal to begin</param>    /// <param name="end">less than or equal to end</param>    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsInRange(this DateTime o, DateTime begin, DateTime end)
    {
      return o &gt;= begin &amp;&amp; o &lt;= end;
    }
 
    /// &lt;summary&gt;
    /// Inside?    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;param name="values"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsIn&lt;T&gt;(this T o, params T[] values)
    {
      return (o);
    }
 
    /// &lt;summary&gt;
    /// Is it null or ""?    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsNullOrEmpty(this object o)
    {
      if (o == null || o == ) return true;
      return () == "";
    }
    /// &lt;summary&gt;
    /// Is it null or ""?    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsNullOrEmpty(this Guid? o)
    {
      if (o == null) return true;
      return o == ;
    }
    /// &lt;summary&gt;
    /// Is it null or ""?    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsNullOrEmpty(this Guid o)
    {
      if (o == null) return true;
      return o == ;
    }
 
    /// &lt;summary&gt;
    /// Is there a value? (Contrary to IsNullOrEmpty)    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsValuable(this object o)
    {
      if (o == null) return false;
      return () != "";
    }
    /// &lt;summary&gt;
    /// Is there a value? (Contrary to IsNullOrEmpty)    /// &lt;/summary&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsValuable(this IEnumerable&lt;object&gt; o)
    {
      if (o == null || () == 0) return false;
      return true;
    }
 
    /// &lt;summary&gt;
    /// Is it zero?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsZero(this object o)
    {
      return (o == null || () == "0");
    }
 
    /// &lt;summary&gt;
    /// Is it INT?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsInt(this object o)
    {
      if (o == null) return false;
      return ((), @"^\d+$");
    }
    /// &lt;summary&gt;
    /// Not INT?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsNoInt(this object o)
    {
      if (o == null) return true;
      return !((), @"^\d+$");
    }
 
    /// &lt;summary&gt;
    /// Is it money?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsMoney(this object o)
    {
      if (o == null) return false;
      double outValue = 0;
      return ((), out outValue);
    }
 
    /// &lt;summary&gt;
    /// Is it the email?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsEamil(this object o)
    {
      if (o == null) return false;
      return ((), @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");
    }
 
    /// &lt;summary&gt;
    /// Is it a cell phone?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsMobile(this object o)
    {
      if (o == null) return false;
      return ((), @"^\d{11}$");
    }
 
    /// &lt;summary&gt;
    /// Is it a landline?    /// &lt;/summary&gt;
    public static bool IsTelephone(this object o)
    {
      if (o == null) return false;
      return ((), @"^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{8}$");
 
    }
 
    /// &lt;summary&gt;
    /// Is it an ID card?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsIDcard(this object o)
    {
      if (o == null) return false;
      return ((), @"^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$");
    }
 
    /// &lt;summary&gt;
    ///Is it suitable for regular matching?    /// &lt;/summary&gt;
    /// &lt;param name="o"&gt;&lt;/param&gt;
    /// <param name="begin">greater than or equal to begin</param>    /// <param name="end">less than or equal to end</param>    /// &lt;returns&gt;&lt;/returns&gt;
    public static bool IsMatch(this object o, string pattern)
    {
      if (o == null) return false;
      Regex reg = new Regex(pattern);
      return (());
    }
  }
}