C# check if type is nullable
This is a nice little snippet to check if a type is nullable:
public static bool IsNullableType(Type type) {
if(!type.IsGeneric) {
return false;
}
if(type.GetGenericTypeDefinition() == typeof(Nullable<>)) {
return true;
}
else {
return false;
}
}
This is a restructured version of Snippet: Check if type is Nullable (C# 2.0) or not (C#)
Related posts: