New issue 50 by daniel.k...@gmail.com: Nullable types
http://code.google.com/p/linqtoexcel/issues/detail?id=50
How can I return null from an empty cell instead of default value?
I use
row[15].Cast<double>();
I see this in your code
public T Cast<T>()
{
return (Value == null || Value is DBNull) ?
default(T) :
(T)Convert.ChangeType(Value, typeof(T));
}
but also this in extensions
public static object Cast(this object @object, Type castType)
{
//return null for DBNull values
if (@object.GetType() == typeof(DBNull))
return null;
//checking for nullable types
if (castType.IsGenericType &&
castType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
castType = Nullable.GetUnderlyingType(castType);
}
return Convert.ChangeType(@object, castType);
}
thx
Try row[15].Cast<double?>();
I have tried this first but cell.Cast has check for null value and doesn't
care if type is nullable
Comment #3 on issue 50 by paulyo...@gmail.com: Nullable types
http://code.google.com/p/linqtoexcel/issues/detail?id=50
(No comment was entered for this change.)
Hi Daniel,
I'm trying to reproduce this issue but cannot.
cell.Cast<double>() returns 0, which you don't want.
cell.Cast<double?>() return null because null is double? default's value.
Can you try cell.Cast<double?>() (with the question mark) and see if it
returns null for you.
Thanks for helping me out!