using System; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; namespace System.ComponentModel { /// Provides a type converter to convert objects to and from other representations. // Token: 0x020000C3 RID: 195 public class TimeSpanConverter : TypeConverter { /// Gets a value indicating whether this converter can convert an object in the given source type to a using the specified context. /// true if this converter can perform the conversion; otherwise, false. /// An that provides a format context. /// A that represents the type you wish to convert from. // Token: 0x0600066C RID: 1644 RVA: 0x00010CE0 File Offset: 0x0000EEE0 public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } /// Gets a value indicating whether this converter can convert an object to the given destination type using the context. /// true if this converter can perform the conversion; otherwise, false. /// An that provides a format context. /// A that represents the type you wish to convert to. /// /// is null. /// /// is not a valid value for the target type. // Token: 0x0600066D RID: 1645 RVA: 0x00010CFC File Offset: 0x0000EEFC public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return destinationType == typeof(string) || destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor) || base.CanConvertTo(context, destinationType); } /// Converts the given object to a . /// An that represents the converted value. /// An that provides a format context. /// An optional . If not supplied, the current culture is assumed. /// The to convert. /// The conversion cannot be performed. /// /// is not a valid value for the target type. // Token: 0x0600066E RID: 1646 RVA: 0x00010D38 File Offset: 0x0000EF38 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value.GetType() == typeof(string)) { string text = (string)value; try { return TimeSpan.Parse(text); } catch { throw new FormatException(text + "is not valid for a TimeSpan."); } } return base.ConvertFrom(context, culture, value); } /// Converts the given object to another type. /// The converted object. /// A formatter context. /// The culture into which will be converted. /// The object to convert. /// The type to convert the object to. // Token: 0x0600066F RID: 1647 RVA: 0x00010DB8 File Offset: 0x0000EFB8 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is TimeSpan) { TimeSpan timeSpan = (TimeSpan)value; if (destinationType == typeof(string) && value != null) { return timeSpan.ToString(); } if (destinationType == typeof(global::System.ComponentModel.Design.Serialization.InstanceDescriptor)) { ConstructorInfo constructor = typeof(TimeSpan).GetConstructor(new Type[] { typeof(long) }); return new global::System.ComponentModel.Design.Serialization.InstanceDescriptor(constructor, new object[] { timeSpan.Ticks }); } } return base.ConvertTo(context, culture, value, destinationType); } } }