<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.3" />

InfiniteTimeSpanConverter

Converts between a string and the standard infinite TimeSpan value.
using System.ComponentModel; using System.Globalization; namespace System.Configuration { public sealed class InfiniteTimeSpanConverter : ConfigurationConverterBase { private static readonly TypeConverter s_timeSpanConverter = TypeDescriptor.GetConverter(typeof(TimeSpan)); public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) { ConfigurationConverterBase.ValidateType(value, typeof(TimeSpan)); if (!((TimeSpan)value == TimeSpan.MaxValue)) return s_timeSpanConverter.ConvertToInvariantString(value); return "Infinite"; } public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) { if (!((string)data == "Infinite")) return s_timeSpanConverter.ConvertFromInvariantString((string)data); return TimeSpan.MaxValue; } } }