Skip to content

Commit f33854f

Browse files
committed
Fix unbox cast from DateTime
1 parent 1b00a39 commit f33854f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Build/CommonAssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
//
1616
// You can specify all the values or you can default the Revision and Build Numbers
1717
// by using the '*' as shown below:
18-
[assembly: AssemblyVersion("1.0.57.0")]
19-
[assembly: AssemblyFileVersion("1.0.57.0")]
18+
[assembly: AssemblyVersion("1.0.58.0")]
19+
[assembly: AssemblyFileVersion("1.0.58.0")]

Griddly.Mvc/GriddlyColumn.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public override object RenderCellValue(object row, bool stripHtml = false)
135135
else if (value is Enum)
136136
value = Extensions.ToStringDescription((Enum)value);
137137
else if (value != null && value.GetType().HasCastOperator<DateTime>())
138-
value = (DateTime)value;
138+
// value = (DateTime)value; -- BAD: can't unbox a value type as a different type
139+
value = Convert.ChangeType(value, typeof(DateTime));
139140

140141
if (stripHtml && value is string)
141142
value = HttpUtility.HtmlDecode(_htmlMatch.Replace(value.ToString(), "").Trim().Replace(" ", " "));

Griddly.Mvc/GriddlyExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
153153
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
154154
values[value.Key] = value.Value;
155155
else if (t.HasCastOperator<DateTime>())
156-
values[value.Key] = (DateTime)value.Value;
156+
// values[value.Key] = (DateTime)value.Value; -- BAD: can't unbox a value type as a different type
157+
values[value.Key] = Convert.ChangeType(value.Value, typeof(DateTime));
158+
157159
}
158160
}
159161

@@ -174,7 +176,8 @@ public static string Current(this UrlHelper helper, object routeValues = null, b
174176
if (t.IsPrimitive || t.IsEnum || t == typeof(Decimal) || t == typeof(String) || t == typeof(DateTime) || t == typeof(TimeSpan) || t == typeof(DateTimeOffset))
175177
values[value.Key] = value.Value;
176178
else if (t.HasCastOperator<DateTime>())
177-
values[value.Key] = (DateTime)value.Value;
179+
// values[value.Key] = (DateTime)value.Value; -- BAD: can't unbox a value type as a different type
180+
values[value.Key] = Convert.ChangeType(value.Value, typeof(DateTime));
178181
}
179182
}
180183
}

0 commit comments

Comments
 (0)