Esempio n. 1
0
        private static bool TryParseColor(ref Color color, ColorRepresentanion colorRep, string text)
        {
            bool result = false;

            switch (colorRep)
            {
            case ColorRepresentanion.None:
                result = false;
                break;

            case ColorRepresentanion.Hex:
                string hexRepresentation = GetHexNumber(text);
                color  = ColorTranslator.FromHtml(hexRepresentation);
                result = true;
                break;

            case ColorRepresentanion.CommaSeperated:
                result = TryParseCommaSeperatedColor(ref color, text);
                break;

            default:
                result = false;
                break;
            }
            return(result);
        }
Esempio n. 2
0
        public static bool TryGetColor(string colorName, out Color color)
        {
            color = Color.Empty;
            ColorRepresentanion colorRep = ClassifyColor(colorName);

            return(TryParseColor(ref color, colorRep, colorName));
        }
Esempio n. 3
0
        private static ColorRepresentanion ClassifyColor(string text)
        {
            ColorRepresentanion colorRep = ColorRepresentanion.None;

            if (text.Contains(','))
            {
                colorRep = ColorRepresentanion.CommaSeperated;
            }
            else
            {
                colorRep = ColorRepresentanion.Hex;
            }

            //if (text.StartsWith("#") || text.StartsWith("$") || IsHexLetters(text))
            //    colorRep = ColorRepresentanion.Hex;
            //colorRep = ColorRepresentanion.Hex;
            return(colorRep);
        }