关于 UtilConvert Bug 返回

C#论坛 老数据
1 2188

很久了 ! 很久了 ! 麻烦作者大人修复一下 ObjToInt的Bug行不行?  

/// <summary>

        /// 

        /// </summary>

        /// <param name="thisValue"></param>

        /// <returns></returns>

        public static int ObjToInt2(this object thisValue)

        {

            int reval = 0;

            if (thisValue == null) return 0;

            if (thisValue is Enum)

            {

                return (int)thisValue;

            }

            if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))

            {

                return reval;

            }

            return reval;

        }



/// <summary>

        /// 

        /// </summary>

        /// <param name="thisValue"></param>

        /// <param name="errorValue"></param>

        /// <returns></returns>

        public static int ObjToInt2(this object thisValue, int errorValue)

        {

            int reval = 0;

            if (thisValue == null) return 0;

            if (thisValue is Enum)

            {

                return (int)thisValue;

            }

            if (thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out reval))

            {

                return reval;

            }

            return errorValue;

        }


多一个判断Enum行不行 ? 不然每次都改挺麻烦的. 修复一下 ? 

热忱回答1