TimeSpan configuration values in .NET Core

added by DotNetKicks
11/25/2019 5:34:52 PM

785 Views

You can use a standard string format for TimeSpan values in configuration files. Sometimes you need to make TimeSpan values configurable. I often see configuration files that look like this: { "SeatingDurationInSeconds": "9000" } Code can read such values from configuration files like this: var seatingDuration = TimeSpan.FromSeconds(Configuration.GetValue ("SeatingDurationInSeconds")); This works, but is abstruse.


0 comments