获得Boolean NULL 相关的值

2014-11-14 10:07:21  访问(1784) 赞(0) 踩(0)

 /// <summary>
        /// 获得Boolean NULL 相关的值
        /// </summary>
        /// <param name="oValue"></param>
        /// <returns></returns>
        private static bool? GetBooleanNullByObj(object oValue)
        {
            if (oValue == null || oValue == DBNull.Value)
                return null;

            if (oValue is Boolean)
                return (bool?)oValue;

            string str = oValue.ToString();

            if (str.Length == 0)
                return null;

            str = str.Trim();

            if (str.Length == 0)
                return null;

            if (str == "1")
                return true;

            if (str == "0")
                return false;

            throw new Exception("str == " + str + " 不是有效的Boolean值。");
        }


标签:获得Boolean NULL 相关的值 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)