| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.ComponentModel; |
| | | 6 | | using System.Globalization; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | internal class TimeSpanOrInfiniteConverter : TimeSpanConverter |
| | | 11 | | { |
| | | 12 | | public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) |
| | | 13 | | { |
| | 0 | 14 | | if (!(value is TimeSpan timeSpan)) |
| | 0 | 15 | | throw new ArgumentException(SR.Format(SR.ConfigInvalidClassFactoryValue, value.GetType().Name, |
| | 0 | 16 | | type.Name)); |
| | | 17 | | |
| | 0 | 18 | | return timeSpan == TimeSpan.MaxValue ? "Infinite" : base.ConvertTo(ctx, ci, timeSpan, type); |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) |
| | | 22 | | { |
| | 24 | 23 | | return (string)data == "Infinite" ? TimeSpan.MaxValue : base.ConvertFrom(ctx, ci, data); |
| | | 24 | | } |
| | | 25 | | } |
| | | 26 | | } |