Without setting a format on DateTime properties, excel seems to format them as integers. For example,
10/26/2016 prints as 42669.
I see that I can easily format a DateTime property if I know it in advance, like this:
mapper.Format<MyObject>("yyyy-MM-dd", x => x.MyDateField)
I tried to make it generic, so I don't need a custom method for every one of my types:
foreach (var property in typeof(T).GetProperties())
{
if (property.PropertyType == typeof(DateTime) ||
property.PropertyType == typeof(DateTime?))
{
mapper.Format<T>("yyyy-MM-dd", x => property.GetValue(x));
}
}
But this fails with "Unable to cast object of type 'System.Linq.Expressions.InstanceMethodCallExpressionN' to type 'System.Linq.Expressions.UnaryExpression'."
Would you help me figure this out, or consider building in a default format for DateTime that isn't an integer?
Without setting a format on DateTime properties, excel seems to format them as integers. For example, 10/26/2016 prints as 42669.
I see that I can easily format a DateTime property if I know it in advance, like this:
mapper.Format<MyObject>("yyyy-MM-dd", x => x.MyDateField)
I tried to make it generic, so I don't need a custom method for every one of my types:
But this fails with "Unable to cast object of type 'System.Linq.Expressions.InstanceMethodCallExpressionN' to type 'System.Linq.Expressions.UnaryExpression'."
Would you help me figure this out, or consider building in a default format for DateTime that isn't an integer?