Svg.SvgViewBoxConverter.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, System culture, object value ) : object
context ITypeDescriptorContext An that provides a format context.
culture System The to use as the current culture.
value object The to convert.
return object
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value is string)
            {
                string[] coords = ((string)value).Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (coords.Length != 4)
                {
                    throw new SvgException("The 'viewBox' attribute must be in the format 'minX, minY, width, height'.");
                }

                return new SvgViewBox(float.Parse(coords[0], NumberStyles.Float, CultureInfo.InvariantCulture),
                    float.Parse(coords[1], NumberStyles.Float, CultureInfo.InvariantCulture),
                    float.Parse(coords[2], NumberStyles.Float, CultureInfo.InvariantCulture),
                    float.Parse(coords[3], NumberStyles.Float, CultureInfo.InvariantCulture));
            }

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