Accord.Controls.RangeTypeConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() public method

Converts the given object to the type of this converter, using the specified context and culture information.
The conversion cannot be performed.
public ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext An that provides a format context.
culture System.Globalization.CultureInfo The to use as the current culture.
value object The to convert.
return object
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value == null)
                return base.ConvertFrom(context, culture, value);

            String str = value as String;

            if (str == null)
                return base.ConvertFrom(context, culture, value);

            str = str.Replace("(", String.Empty);
            str = str.Replace(")", String.Empty);
            str = str.Replace("[", String.Empty);
            str = str.Replace("]", String.Empty);

            String[] parts = str.Split(';');
            string a = parts[0];
            string b = parts[1];

            if (context.PropertyDescriptor.PropertyType == typeof(IntRange))
            {
                int max = int.Parse(a);
                int min = int.Parse(b);
                return new IntRange(min, max);

            }
            else if (context.PropertyDescriptor.PropertyType == typeof(DoubleRange))
            {
                double max = double.Parse(a);
                double min = double.Parse(b);
                return new DoubleRange(min, max);
            }
            

            return base.ConvertFrom(context, culture, value);
        }