.NET: How do I tell if a type is nullable? [duplicate]
Possible Duplicate:
How to check if an object is nullable?
I have a System.Type object which may be a Nullable&l开发者_StackOverflow中文版t;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.
Possible duplicate:
How to check if an object is nullable?
if not..
bool IsNullableType(Type theType)
{
return (theType.IsGenericType &&
theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
精彩评论