C# 扩展类

    static class ClassExtension
    {
        public static string NullableToString(this object o)
        {
            try
            {
                return o.ToString();
            }
            catch
            {
                return "";
            }
        }
        public static bool NullableToBool(this object o)
        {
            try
            {
                if (o.ToString() == "True")
                    return true;
                else
                    return false;
            }
            catch
            {
                return false;
            }
        }
        public static int NullableToInt(this object o)
        {
            try
            {
                return int.Parse(o.ToString());
            }
            catch
            {
                return 0;
            }
        }
    }
原文地址:https://www.cnblogs.com/ilookbo/p/4155654.html