取得一个对象的具体类型

 public static string GetType(object source)
 {
    if (source == null)   

       {
                return "null";
        }

            var type = source.GetType();
            switch (Type.GetTypeCode(type))
            {
                //数值型
                case TypeCode.Byte:
                case TypeCode.Decimal:
                case TypeCode.Double:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.SByte:
                case TypeCode.Single:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                case TypeCode.UInt64:
                    return source.ToString();
                case TypeCode.Object:
                    break;
                case TypeCode.Boolean:
                    return (bool)source ? "true" : "false";
                case TypeCode.DBNull:
                    return "null";
                default:
                    return "\"" + source + "\"";
            }

}

原文地址:https://www.cnblogs.com/wangsx/p/2205694.html