Popular Posts
Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... CTE, recursive search WITH DepartmentSearch(DeptID, DeptParent, DeptName, OuID) AS (     -- 找出簽核者所屬部門     SELECT d.DeptID, d.DeptParent, d.DeptName, d.OuID     FR... Create web service client cross SSL with eclipse When creating web service cross SSL using eclipse, it occuss some error like below: And it can't build the client source from this wa...
Stats
MyUtil
using System;

namespace Bruce.Lib
{
    public class BUtil
    {
        /// <summary>
        /// 測試參數中是否含有null或空值
        /// </summary>
        /// <param name="data">任意物件</param>
        /// <returns>含有null、DBNull或空值則為true,反之為false</returns>
        public static bool ContainsNullOrEmpty(params object[] data)
        {
            foreach (object d in data)
            {
                if (d == null || d == DBNull.Value || string.IsNullOrEmpty(d.ToString()))
                    return true;
            }
            return false;
        }
        /// <summary>
        /// 將任意物件轉成字串,免去再判斷null或DBNull的處理
        /// </summary>
        /// <param name="data">任意物件</param>
        /// <returns></returns>
        public static string StringValue(object data)
        {
            return data == null || data == DBNull.Value ? string.Empty : Convert.ToString(data);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string Summary(object data, int length)
        {
            if (length < 1) throw new ArgumentException();
            string str = StringValue(data);
            return str.Length > length ? str.Substring(0, length) + "..." : str;
        }
    }
}