tags:

views:

260

answers:

3

I know merely checking for whether the type is not a value type is not sufficient. How can i account for those Nullable?

DUPLICATE

http://stackoverflow.com/questions/374651/how-to-check-if-an-object-is-nullable

+5  A: 

You can use Nullable.GetUnderlyingType that will return null if the type is not nullable.

Think Before Coding
+1  A: 

have you tried the keyword default(YourType) ?

Whether T will be a reference type or a value type.

If T is a value type, whether it will be a numeric value or a struct.

Nicolas Dorier
A: 

This also works:

 bool nullable = yourType.IsGenericType && yourType.GetGenericTypeDefinition().Equals(typeof(Nullable<>))
H-Man2