Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data.... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement...
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;
        }
    }
}