using System; using System.Globalization; namespace System.ComponentModel { /// Provides a base type converter for nonfloating-point numerical types. // Token: 0x02000059 RID: 89 public abstract class BaseNumberConverter : TypeConverter { // Token: 0x170000F3 RID: 243 // (get) Token: 0x0600037F RID: 895 internal abstract bool SupportHex { get; } /// Determines if this converter can convert an object in the given source type to the native type of the converter. /// true if this converter can perform the operation; otherwise, false. /// An that provides a format context. /// A that represents the type from which you want to convert. // Token: 0x06000380 RID: 896 RVA: 0x0000AADC File Offset: 0x00008CDC public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType); } /// Returns 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 operation; otherwise, false. /// An that provides a format context. /// A that represents the type to which you want to convert. // Token: 0x06000381 RID: 897 RVA: 0x0000AAFC File Offset: 0x00008CFC public override bool CanConvertTo(ITypeDescriptorContext context, Type t) { return t.IsPrimitive || base.CanConvertTo(context, t); } /// Converts the given object to the converter's native type. /// An that represents the converted value. /// An that provides a format context. /// A that specifies the culture to represent the number. /// The object to convert. /// /// is not a valid value for the target type. /// The conversion cannot be performed. // Token: 0x06000382 RID: 898 RVA: 0x0000AB14 File Offset: 0x00008D14 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (culture == null) { culture = CultureInfo.CurrentCulture; } string text = value as string; if (text != null) { try { if (this.SupportHex) { if (text.Length >= 1 && text[0] == '#') { return this.ConvertFromString(text.Substring(1), 16); } if (text.StartsWith("0x") || text.StartsWith("0X")) { return this.ConvertFromString(text, 16); } } NumberFormatInfo numberFormatInfo = (NumberFormatInfo)culture.GetFormat(typeof(NumberFormatInfo)); return this.ConvertFromString(text, numberFormatInfo); } catch (Exception ex) { throw new Exception(value.ToString() + " is not a valid value for " + this.InnerType.Name + ".", ex); } } return base.ConvertFrom(context, culture, value); } /// Converts the specified object to another type. /// An that represents the converted value. /// An that provides a format context. /// A that specifies the culture to represent the number. /// The object to convert. /// The type to convert the object to. /// /// is null. /// The conversion cannot be performed. // Token: 0x06000383 RID: 899 RVA: 0x0000AC24 File Offset: 0x00008E24 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value == null) { throw new ArgumentNullException("value"); } if (culture == null) { culture = CultureInfo.CurrentCulture; } if (destinationType == typeof(string) && value is IConvertible) { return ((IConvertible)value).ToType(destinationType, culture); } if (destinationType.IsPrimitive) { return Convert.ChangeType(value, destinationType, culture); } return base.ConvertTo(context, culture, value, destinationType); } // Token: 0x06000384 RID: 900 internal abstract string ConvertToString(object value, NumberFormatInfo format); // Token: 0x06000385 RID: 901 internal abstract object ConvertFromString(string value, NumberFormatInfo format); // Token: 0x06000386 RID: 902 RVA: 0x0000AC9C File Offset: 0x00008E9C internal virtual object ConvertFromString(string value, int fromBase) { if (this.SupportHex) { throw new NotImplementedException(); } throw new InvalidOperationException(); } // Token: 0x04000121 RID: 289 internal Type InnerType; } }