public static Type GetConcreteTypeIfNullable(this Type type)
{
if (type == null)
{
throw new ArgumentNullException("type", "type cannot be null.");
}
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
return type.GetGenericArguments()[0];
}
return type;
}