.NET:如何判断类型是否可为空?

时间:2010-12-13 08:45:49

标签: .net

  

可能重复:
  How to check if an object is nullable?

我有一个System.Type对象,可能是Nullable<T>。我如何在运行时确定这个?

注意:此时我并不关心T是什么,我只需要知道它是否为Nullable。

1 个答案:

答案 0 :(得分:12)

可能重复:

How to check if an object is nullable?

如果没有..

bool IsNullableType(Type theType)
{
    return (theType.IsGenericType && 
    theType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
}
相关问题