Artemis.Engine.GameConstants.ReadColour C# (CSharp) Метод

ReadColour() приватный Метод

Read a colour value from a string in the xml file.
private ReadColour ( string s, Color defaultVal ) : Color
s string
defaultVal Color
Результат Color
        private Color ReadColour(string s, Color defaultVal)
        {
            // If the given colour string is a name, attempt
            // to find it as a static property of Color.

            // The binding flags when searching for the color
            // property in typeof(Color).
            var binding = BindingFlags.Public |
                          BindingFlags.Static |
                          BindingFlags.FlattenHierarchy;

            var prop = typeof(Color).GetProperty(s, binding);

            if (prop != null)
            {
                return (Color)prop.GetValue(null, null);
            }

            if (!Regex.IsMatch(s, COLOUR_REGEX))
            {
                // Log that we couldn't figure out the colour.
                return defaultVal;
            }

            var val = Convert.ToInt32(s, 16);

            var r = 0xff & (val >> 16);
            var g = 0xff & (val >> 8);
            var b = 0xff & val;

            return new Color(r, g, b);
        }