#if NET_2_0
using System.ComponentModel;
+using System.Globalization;
namespace System.Configuration
{
- public class TimeSpanMinutesOrInfiniteConverter: TimeSpanMinutesConverter
+ public sealed class TimeSpanMinutesOrInfiniteConverter: TimeSpanMinutesConverter
{
+ public override object ConvertFrom (ITypeDescriptorContext ctx, CultureInfo ci, object data)
+ {
+ if ((string)data == "Infinite")
+ return TimeSpan.MaxValue;
+ else
+ return base.ConvertFrom(ctx, ci, data);
+ }
+
+ public override object ConvertTo (ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type)
+ {
+ /* don't use "value is TimeSpan" here, since
+ * we want to generate both a NRE on null
+ * value, and ArgumentException on non-null,
+ * but non-TimeSpan. */
+ if (value.GetType () != typeof (TimeSpan))
+ throw new ArgumentException ();
+
+ if (((TimeSpan)value) == TimeSpan.MaxValue)
+ return "Infinite";
+ else
+ return base.ConvertTo (ctx, ci, value, type);
+ }
}
}
#endif