开发者

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

开发者 https://www.devze.com 2023-01-30 01:35 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: How to check if an object is nullable?
This question already has answers here: Closed 12 years ago.

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<>)));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消