DateOnlyTimeOnly.AspNet
DateOnlyTimeOnly.AspNet copied to clipboard
The package mutates runtime behavior
Description
At the moment this package messes with the TypeConverter
attribute of DateOnly
and TimeOnly
:
https://github.com/maxkoshevoi/DateOnlyTimeOnly.AspNet/blob/ee1b2bd9b37ec13268f2e35428337a887083bdb0/DateOnlyTimeOnly.AspNet/Extensions/MvcOptionsExtensions.cs#L11-L12
Such approach should be avoided, because it unintentionally changes documented behavior of the runtime. For example,
var date = TypeDescriptor.GetConverter(typeof(DateOnly)).ConvertFromString("01.01.0001");
Expected behavior:
System.NotSupportedException: 'TypeConverter cannot convert from System.String.'
should be thrown
Actual behavior:
Exception is not thrown
Proposal
The package should not mutate runtime (potentially breaking code, that relies on documented and therefore expected behavior). It's possible to add support of DateOnly
and TimeOnly
for AspNetCore via ModelBinders
The goal is to bring DateOnly
and TimeOnly
more in line with DateTime
(since they are basically subsets of that type).
This does work:
var dateTime = TypeDescriptor.GetConverter(typeof(DateTime)).ConvertFromString("01.01.0001");
so why it shouldn't for DateOnly
and TimeOnly
?
It's not question for me. You may address it to dotnet/runtime.
At the moment the things are as they are. Package made for AspNetCore should not change runtime in general. Especially, when the same behavior could be achieved via tools of the AspNetCore framework itself