In a project I need to configure some third party library via the Micorosoft.Extensions.Configuration.
The library gives an options class and I used the configurationSection.Bind(optionsClassInstance) method to bind the values.
It works well except the nested TimeSpan value. I can't figure out what the json structure of a timespan is so it could be bound.
There are no errors. The values from the json are simply not bound.
So far I just used "timespan": { "Days": 0, "Hours": 1, "Minutes": 0 }
Thanks to the answer I tested successfully the given values with the given results:
1.02:03:04.567 = 1 day, 2 hours, 3 minutes, 4 seconds, 567 milliseconds
1.02:03:04 = 1 day, 2 hours, 3 minutes, 4 seconds, 0 milliseconds
02:03:04 = 0 days, 2 hours, 3 minutes, 4 seconds, 0 milliseconds
03:04 = 0 days, 3 hours, 4 minutes, 0 seconds, 0 milliseconds
04 = 4 days, 0 hours, 0 minutes, 0 seconds, 0 milliseconds
The following configuration providers derive from FileConfigurationProvider : JSON configuration provider. XML configuration provider. INI configuration provider.
The appsettings. json file is generally used to store the application configuration settings such as database connection strings, any application scope global variables, and much other information.
appsettings. json is one of the several ways, in which we can provide the configuration values to ASP.NET core application. You will find this file in the root folder of our project. We can also create environment-specific files like appsettings.
Timespan format in .net core is D.HH:mm:nn
(so "1.02:03:04" is 1 day, 2 hours, 3 mins, 4 seconds).
javascript wont be able to read that (we use a custom JsonConverter for timespan objects for that reason), but .Net can.
{"timespan":"1.02:03:04"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With