public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value.GetType() == typeof(string)) { try { ColorValue value2 = ColorValue.Parse((string)value); if (((string)value).Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length == 3) { value2.Alpha *= 255f; } return(value2 / 255f); } catch (Exception) { return(value); } } return(base.ConvertFrom(context, culture, value)); }
public static ColorValueRange Parse(string text) { ColorValueRange range; if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("The parsableText parameter cannot be null or zero length."); } string[] strArray = text.Split(new char[] { ';' }); if (strArray.Length != 2) { throw new FormatException(string.Format("Cannot parse the text '{0}' because it does not have 2 parts separated by \";\" in the form (0 1) with optional parenthesis.", text)); } try { range = new ColorValueRange(ColorValue.Parse(strArray[0].Trim()), ColorValue.Parse(strArray[1].Trim())); } catch (Exception) { throw new FormatException("The parts of the colors must be decimal numbers."); } return(range); }