How to determine if a type is a Nullable
Filed in c# on Aug.17, 2007
Yesterday I had a problem determining whether a supplied type was of the type Nullable
Type mt = suppliedVar.GetType();
if(mt.IsGenericType && mt.GetGenericTypeDefinition() ==
typeof(Nullable<>)) && mt.GetGenericArguments().Length>0)
{
if(mt.GetGenericArguments()[0].IsEnum) {
// Type is a Nullable
}
}
Twitter
Leave a Reply