public static string Serialize(ColourInfo c) { // SingleColour if (c.TopLeft.Equals(c.TopRight) && c.TopLeft.Equals(c.BottomRight) && c.TopLeft.Equals(c.BottomLeft)) { return(Color4Converter.Serialize(c.TopLeft)); } // GradientHorizontal if (c.TopLeft.Equals(c.BottomLeft) && c.TopRight.Equals(c.BottomRight) && !c.TopLeft.Equals(c.TopRight)) { return($"gradient(horizontal, {Color4Converter.Serialize(c.TopLeft)}, {Color4Converter.Serialize(c.TopRight)})"); } // GradientVertical if (c.TopLeft.Equals(c.TopRight) && c.BottomLeft.Equals(c.BottomRight) && !c.TopLeft.Equals(c.BottomLeft)) { return($"gradient(vertical, {Color4Converter.Serialize(c.TopLeft)}, {Color4Converter.Serialize(c.BottomRight)})"); } // Full serialization var tl = Color4Converter.Serialize(c.TopLeft); var tr = Color4Converter.Serialize(c.TopRight); var br = Color4Converter.Serialize(c.BottomRight); var bl = Color4Converter.Serialize(c.BottomLeft); return($"{tl}, {tr}, {br}, {bl}"); }
public static string Serialize(EdgeEffectParameters p) { if (p.Type == EdgeEffectType.None) { return("None"); } var list = new List <string>(); if (p.Hollow) { list.Add("true"); } if (p.Offset != default || list.Count > 0) { list.Add($"({Vector2Converter.Serialize(p.Offset)})"); } if (p.Roundness != default || list.Count > 0) { list.Add(p.Roundness.ToString()); } if (p.Radius != default || list.Count > 0) { list.Add(p.Radius.ToString()); } list.Add(Color4Converter.Serialize(p.Colour)); list.Add(p.Type.ToString()); list.Reverse(); return(string.Join(", ", list)); }
public static ColourInfo Deserialize(string data) { data = data.Trim(); string[] parts; if (data.StartsWith("gradient(", StringComparison.OrdinalIgnoreCase) && data.EndsWith(')')) { parts = data.Substring(9, data.Length - 10).SplitByComma(); var direction = parts[0]; if (direction.Equals("vertical", StringComparison.OrdinalIgnoreCase)) { return(ColourInfo.GradientVertical( c1: Color4Converter.Deserialize(parts[1]), c2: Color4Converter.Deserialize(parts[2]))); } if (direction.Equals("horizontal", StringComparison.OrdinalIgnoreCase)) { return(ColourInfo.GradientHorizontal( c1: Color4Converter.Deserialize(parts[1]), c2: Color4Converter.Deserialize(parts[2]))); } } parts = data.SplitByComma(); if (parts.Length == 1) { return(ColourInfo.SingleColour(Color4Converter.Deserialize(parts[0]))); } if (parts.Length == 4) { return new ColourInfo { TopLeft = Color4Converter.Deserialize(parts[0]), TopRight = Color4Converter.Deserialize(parts[1]), BottomRight = Color4Converter.Deserialize(parts[2]), BottomLeft = Color4Converter.Deserialize(parts[3]) } } ; throw new FormatException($"Unrecognized {nameof(ColourInfo)} '{data}'."); } }
public static EdgeEffectParameters Deserialize(string data) { var parts = data.SplitByComma(); if (parts.Length == 0) { throw new MarkupException($"Unrecognized {nameof(EdgeEffectParameters)}."); } var edge = new EdgeEffectParameters { Type = Enum.Parse <EdgeEffectType>(parts[0], ignoreCase: true), }; if (parts.Length > 1) { edge.Colour = Color4Converter.Deserialize(parts[1]); } if (parts.Length > 2) { edge.Radius = float.Parse(parts[2]); } if (parts.Length > 3) { edge.Roundness = float.Parse(parts[3]); } if (parts.Length > 4) { edge.Offset = Vector2Converter.Deserialize(parts[4].Substring(1, parts[4].Length - 2)); } if (parts.Length > 5) { edge.Hollow = bool.Parse(parts[5]); } if (parts.Length > 6) { throw new MarkupException($"Unknown {nameof(EdgeEffectParameters)} component '{parts[6]}'."); } return(edge); }
public void Deserialize(string data, Type type, out object value) => value = (SRGBColour)Color4Converter.Deserialize(data);
public void Serialize(object value, Type type, out string data) => data = Color4Converter.Serialize((SRGBColour)value);