I'm trying to box values to an IEnumerable for a JsonConverter to be able to loop through dynamic data. However, I'm running into problems when trying to box a list of DateTime, or other structs.
var datetime = DateTime.Now ;
var boxed = datetime as object; // Works: boxed is still a DateTime value
var datetimeList = new List<DateTime> { DateTime.Now };
var boxedEnumerable = datetimeList as IEnumerable<object>; // Does not work, boxedEnumerable is null
Casting to an IEnumerable seems to work well for all reference types, but not value types.
Note: The non-generic IEnumerable class can be used for these types of conversions instead of IEnumerable.