using System; using System.Collections.Generic; using System.Linq; using Windows.Data.Xml.Dom; using Windows.UI; namespace FoxTube { public static class Extensions { public static Uri ToUri(this string url) { try { return new Uri(url); } catch { return null; } } public static XmlDocument ToXml(this string text) { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(text); return doc; } catch { return null; } } public static bool Belongs(this T obj, params T[] args) => args.Contains(obj); public static string ToHex(this Color color) => $"#{color.R:X}{color.G:X}{color.B:X}"; public static Color FromHex(this Color parent, string hex) { hex = hex.Replace("#", ""); List values = new List(); for(int k = 0; k < hex.Length; k++) values.Add(byte.Parse(string.Join("", hex[k], hex[++k]), System.Globalization.NumberStyles.HexNumber)); return hex.Length switch { 6 => Color.FromArgb(255, values[0], values[1], values[2]), 8 => Color.FromArgb(values[0], values[1], values[2], values[3]), _ => Colors.Black }; } } }