zoukankan      html  css  js  c++  java
  • 取得一个对象的具体类型

     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 + "\"";
                }

    }

  • 相关阅读:
    vs.net 2005, 没有找到MSVCR80D.dll的完美解决方案
    C++内存布局从一个修改私有变量的问题想到的
    堆栈详解
    加载.x文件
    深入分析规则引擎
    高级着色语言HLSL入门(5)
    字符数组,字符指针,Sizeof总结
    C++ 隐式和显式 初始化,类型转换
    fread()和fwrite()函数分析
    结构体 对齐的问题
  • 原文地址:https://www.cnblogs.com/wangsx/p/2205694.html
Copyright © 2011-2022 走看看