Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: How do I tell if a type is nullable? [duplicate]

Tags:

.net

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.

like image 456
Jonathan Allen Avatar asked Dec 13 '10 08:12

Jonathan Allen


1 Answers

Possible duplicate:

How to check if an object is nullable?

if not..

bool IsNullableType(Type theType)
{
    return (theType.IsGenericType && 
    theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
like image 127
Danish Khan Avatar answered Sep 27 '22 19:09

Danish Khan