首页 > 其他分享 >基础延伸

基础延伸

时间:2023-02-21 11:26:17浏览次数:30  
标签:bf return 基础 static ms 延伸 input retval

 1  /// <summary>
 2         /// 对象深拷贝
 3         /// </summary>
 4         /// <typeparam name="T"></typeparam>
 5         /// <param name="obj"></param>
 6         /// <returns></returns>
 7         public static T DeepCopyByBin<T>(this T obj)
 8         {
 9             object retval;
10             using (MemoryStream ms = new MemoryStream())
11             {
12                 BinaryFormatter bf = new BinaryFormatter();
13                 //序列化成流
14                 bf.Serialize(ms, obj);
15                 ms.Seek(0, SeekOrigin.Begin);
16                 //反序列化成对象
17                 retval = bf.Deserialize(ms);
18                 ms.Close();
19             }
20             return (T)retval;
21         }

 

  /// <summary>
        /// 包含中文
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool ContainsChinese(this string input)
        {
            if (string.IsNullOrEmpty(input))
                return false;

            return Regex.IsMatch(input, "[\u4e00-\u9fa5]");
        }

 

标签:bf,return,基础,static,ms,延伸,input,retval
From: https://www.cnblogs.com/xiaobing-R/p/17140236.html

相关文章