5

Possible Duplicate:
How to check if an object is nullable?

I have a System.Type object which may be a Nullable<T>. How would I determine this at runtime?

Note: At this point I don't care what T is, I just need to know whether or not it is a Nullable.

Community
  • 1
  • 1
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
  • 2
    Do you mean it's actually a `Nullable` generic object, or that it's a class and can be a null value? – cjk Dec 13 '10 at 08:48

1 Answers1

13

Possible duplicate:

How to check if an object is nullable?

if not..

bool IsNullableType(Type theType)
{
    return (theType.IsGenericType && 
    theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
Community
  • 1
  • 1
Danish Khan
  • 1,893
  • 5
  • 22
  • 35