System.Drawing.RectangleConverter.ConvertFrom C# (CSharp) Method

ConvertFrom() private method

private ConvertFrom ( ITypeDescriptorContext context, CultureInfo culture, object value ) : object
context ITypeDescriptorContext
culture System.Globalization.CultureInfo
value object
return object
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string strValue = value as string;

            if (strValue != null)
            {
                string text = strValue.Trim();

                if (text.Length == 0)
                {
                    return null;
                }
                else
                {
                    // Parse 4 integer values.
                    //
                    if (culture == null)
                    {
                        culture = CultureInfo.CurrentCulture;
                    }
                    char sep = culture.TextInfo.ListSeparator[0];
                    string[] tokens = text.Split(new char[] { sep });
                    int[] values = new int[tokens.Length];
                    TypeConverter intConverter = TypeDescriptor.GetConverter(typeof(int));
                    for (int i = 0; i < values.Length; i++)
                    {
                        // Note: ConvertFromString will raise exception if value cannot be converted.
                        values[i] = (int)intConverter.ConvertFromString(context, culture, tokens[i]);
                    }

                    if (values.Length == 4)
                    {
                        return new Rectangle(values[0], values[1], values[2], values[3]);
                    }
                    else
                    {
                        throw new ArgumentException(SR.Format(SR.TextParseFailedFormat,
                                                                  "text",
                                                                  text,
                                                                  "x, y, width, height"));
                    }
                }
            }

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