My project has a few Global Date Handlers defined for DateTime:
JsConfig<DateTime>.SerializeFn = time =>
{
return new DateTime(time.Ticks, DateTimeKind.Local).ToString("o");
};
JsConfig<DateTime?>.SerializeFn=
time => {
return time != null ? new DateTime(time.Value.Ticks, DateTimeKind.Local).ToString("o") : null;
};
It seems that those global handlers override the custom scope’s because the following doesn’t seem to work in that the DateTime properties aren’t serialized as DateOnly:
using (var config = JsConfig.With(new Config()
{
DateHandler = DateHandler.ISO8601DateOnly,
}))
{
var objJson = si.ToJson();
}
// si.Date1 or si.Date2 don't get serialized as DateOnly
I saw another post here that says there isno custom date format handling so I guess my question is can I access the Scope information within the SerializeFn func to determine a different way to serialize if the DateHandler is set to ISO8601DateOnly? The reason I need this is I am calling an external API using the HTTP util methods and want to serialize the dates a certain way. Plan B would be to just do it manually as strings but I’m hoping I don’t have to go that route.
In