How to determine if a object type is a built in system type

前端 未结 8 991
醉酒成梦
醉酒成梦 2020-12-14 00:20

I am writing a simple List to CSV converter. My converter checks the all the t\'s in List and grabs all public properties and places them

8条回答
  •  没有蜡笔的小新
    2020-12-14 00:47

    If you are unable to define precisely what a "built in system type" is then it seems likely that you won't know what types are in any answer given. More probably what you want to do is just have a list of the types that you don't want to do this with. Have a "IsSimpleType" method that just does a check against various types.

    The other thing that you may be looking for is Primitive Types. If so look at:

    Type.IsPrimitive (http://msdn.microsoft.com/en-us/library/system.type.isprimitive.aspx)

    The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.

    This doesn't include string but you could add that on manually...

    See also How To Test if Type is Primitive

提交回复
热议问题