zoukankan      html  css  js  c++  java
  • Net 扩展方法集合.

    public static void Main(string[] args)
    {
    #region String Extensions

    string result0 = "[frank%loch".StringConvert4SQLLke(); //替换sql模糊匹配的时候里面的特殊字符

    bool result1 = " abC".CurrentTrimEqualsIgnoreCase(" ABC "); // 比较两字符串是否相同,忽略大小写,字符串前后空白

    List<string> result2 = "1-23@56*78".SplitByMutipleChar('-','@','*').ToList(); //多字母拆分字符串, 输出 { 1 23 56 78 }的集合

    bool result3 = "123".IsNullOrEmpty(); // 判断字符串是否为null或者string.empty.

    bool result4 = "123".IsLengthBetween(2, 4);

    bool result5 = "123".IsShorterThan(2);

    bool result6 = "123".IsLongerThan(2);

    bool result7 = "You are the best".IsContainsAll("You", "the");// result==true,result8==false IsContainsAll 支持多参数输入. 用于判断字符串是否同时包含多个字符串
    bool result8 = "You are the best".IsContainsAll("You", "123");

    bool result9 = "You are the best".IsContainsAny("123", "the"); //result==true,result8==false IsContainsAll 支持多参数输入. 用于判断字符串是否包含多个字符串中的一个

    bool result10 = "You are the best".IsContainsAny("sbc", "123");
    string result11 = "frank".FirstCharToUpter();

    string result12 = " frank ".RTrim(); // 去除字符串右边的空白

    string result13 = " frank ".LTrim(); // 去除字符串左边空白

    string result14 = new List<string>() { "frank", "loch", "hardy" }.ListToSqlIn(false); //用于sql里面的in(x,x,x)语句拼接
    string result15 = new List<string>() { "1", "2", "3" }.ListToSqlIn(true); // result12 = "'frank','loch','hardy'",result12 = "1,2,3"

    bool result16 = "frank".IsEqualsAnyOfThem("hardy", "frank"); // IsEqualsAnyOfItem支持多参数输入,判断字符串是否在多个删除里面

    #endregion

    #region ConvertExtensions // 用于string类型转换int,decimal,datetime

    int result17 = "abc".TryToInt32();
    int result18 = "123".TryToInt32();

    decimal result19 = "1.3".TryToDecimal();
    DateTime result20 = "2015/12/24".TryToDateTime();

    #endregion

    #region ObjectExtensions

    Person p1 = new Person() { Name = "Frank" };
    Person result21 = p1.DeepCopy<Person>(); // 深拷贝

    #endregion

    #region

    List<string> lst = new List<string>() { "123", "456" };
    bool result22 = lst.IsNullOrEmpty(); //判断集合是否有内容
    bool result23 = lst.CountGreaterThanZero();

    List<Person> personList1 = new List<Person>()
    {
    new Person(){Name="Frank"},
    new Person(){Name="Hardy"}
    };

    List<Person> personList2 = new List<Person>()
    {
    new Person(){Name="Frank"},
    new Person(){Name="Hardy"}
    };

    ///public static bool ObjectCollectionEquals<T>(this IEnumerable<T> collection1, IEnumerable<T> collection2, Func<T, T, bool> func),
       /// func里面写入两个对象相同的方法.实现集合对象的比较
    bool result24 = personList1.ObjectCollectionEquals(personList2, (val1, val2) =>
    {
    return val1.Name != val2.Name;
    });

    #endregion

    }

    [Serializable]
    public class Person
    {
    public string Name { get; set; }
    }

  • 相关阅读:
    日期格式化
    面向对象高级编程——使用__slots__
    面向对象编程——实例属性和类属性(六)
    面向对象编程——获取对象信息(五)
    面向对象编程——类方法和静态方法(八)
    面向对象编程——多重继承(七)
    面向对象高级编程——使用@property
    python常用模块——logger模块
    python常用模块——hashlib模块
    面向对象编程——super进阶(十)
  • 原文地址:https://www.cnblogs.com/mingdep/p/5192725.html
Copyright © 2011-2022 走看看