IsPrimitive doesn't include nullable primitive values

c#, primitive, types

Solution

From MSDN:

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

So basically you should expect `Nullable<Int32>` to not be a primitive type.

You could use `Nullable.GetUnderlyingType` to "extract" `Int32` from `Nullable<Int32>`.

Problem

I want to check if a Type is primitive or not and used the following code: ``` return type.IsValueType && type.IsPrimitive; ``` This works fine aslong as the primitive isnt nullable. For example int?, how can I check if the type is a nullable primitive type? (FYI: `type.IsPrimitive == false` on int?)

Original source

Related problems