Merge pull request #364 from directhex/master
[mono.git] / mcs / class / System.Configuration / System.Configuration / TimeSpanMinutesOrInfiniteConverter.cs
index 9e27d59e75dc42173d70b1e6cb5c299192928005..72b387d7b7204255cf5d224056812e6eac893e10 100644 (file)
 #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