/// <summary> /// Clone a color /// </summary> /// <param name="toClone">color source</param> /// <returns>a new color with the same value than the color source</returns> public static CSSColor CloneThis(CSSColor toClone) { if (toClone != null) { return(toClone.Clone() as CSSColor); } else { return(null); } }
/// <summary> /// Try Parse : a same parsing fonction but /// do not raise an exception : return true if succeeded; the color result is a param out /// </summary> /// <param name="s">color value string</param> /// <param name="c">color solution</param> /// <returns>true if succeeded</returns> public static bool TryParse(string s, out CSSColor c) { bool res = false; try { c = CSSColor.ParseColor(s); res = true; } catch { c = null; } return(res); }
/// <summary> /// Constructor with a string representation of a color /// </summary> /// <param name="colorStr">color</param> public CSSColor(string colorStr) { this.Set(colorName, CSSColor.ParseColor(colorStr).Color); }
/// <summary> /// Sets a property that can be border, padding, margin and colors /// </summary> /// <param name="name">property name</param> /// <param name="value">value to set</param> public void Discret(string name, string value) { try { if (name.StartsWith("padding")) { if (name.CompareTo("padding-left") == 0) { this.Padding.Set(Rectangle.leftName, value); } else if (name.CompareTo("padding-right") == 0) { this.Padding.Set(Rectangle.rightName, value); } else if (name.CompareTo("padding-top") == 0) { this.Padding.Set(Rectangle.topName, value); } else if (name.CompareTo("padding-bottom") == 0) { this.Padding.Set(Rectangle.bottomName, value); } else { this.AddIntoBody(name, value); } } else if (name.StartsWith("border")) { if (name.CompareTo("border-left-width") == 0) { this.Border.Set(Rectangle.leftName, value); } else if (name.CompareTo("border-right-width") == 0) { this.Border.Set(Rectangle.rightName, value); } else if (name.CompareTo("border-top-width") == 0) { this.Border.Set(Rectangle.topName, value); } else if (name.CompareTo("border-bottom-width") == 0) { this.Border.Set(Rectangle.bottomName, value); } else if (name.CompareTo("border-left-color") == 0) { this.BorderLeftColor = new CSSColor(value); } else if (name.CompareTo("border-right-color") == 0) { this.BorderRightColor = new CSSColor(value); } else if (name.CompareTo("border-top-color") == 0) { this.BorderTopColor = new CSSColor(value); } else if (name.CompareTo("border-bottom-color") == 0) { this.BorderBottomColor = new CSSColor(value); } else { this.AddIntoBody(name, value); } } else if (name.StartsWith("margin")) { if (name.CompareTo("margin-left") == 0) { this.Margin.Set(Rectangle.leftName, value); } else if (name.CompareTo("margin-right") == 0) { this.Margin.Set(Rectangle.rightName, value); } else if (name.CompareTo("margin-top") == 0) { this.Margin.Set(Rectangle.topName, value); } else if (name.CompareTo("margin-bottom") == 0) { this.Margin.Set(Rectangle.bottomName, value); } else { this.AddIntoBody(name, value); } } else if (name.CompareTo("background-color") == 0) { this.BackgroundColor = new CSSColor(value); } else if (name.CompareTo("color") == 0) { this.ForegroundColor = new CSSColor(value); } else { this.AddIntoBody(name, value); } } catch (FormatException) { this.AddIntoBody(name, value); } }