通过System.Enum获得int值(-1代表没有获得值) - GetIntBySystemEnum

2017-02-26 15:27:51  访问(1811) 赞(0) 踩(0)


        /// <summary>
        /// 通过System.Enum获得int值(-1代表没有获得值) - GetIntBySystemEnum
        /// </summary>
        /// <param name="em"></param>
        /// <param name="iDefault"></param>
        /// <returns></returns>
        public static int GetIntBySystemEnum(System.Enum em)
        {
            if (em == null)
            {

                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "传入参数:System.Enum em为null。"
                    );
            }

            IConvertible ic = (IConvertible)em;

            if (ic == null)
            {
                throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:"
                        + "值IConvertible ic = (IConvertible)em为null。"
                    );
                
            }

            return ic.ToInt32(null);
        }


标签:通过System.Enum获得int值(-1代表没有获得值) - GetIntBySystemEnum 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

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