Exemple #1
0
        static void ToStyle <T>(ExpressionValue expression, ref T controlStyle) where T : struct, IConvertible
        {
            if (expression == null)
            {
                return;
            }
            var tokens = expression.Tokens.Where(tok => tok.Name != Tokens.Pipe).ToArray();

            Debug.Assert(tokens.All(tok => tok.Name == Tokens.Ident || tok.Name == Tokens.Integer || tok.Name == Tokens.Not));
            uint value = EnumConverter <T> .ConvertFromEnum(controlStyle);

            for (uint n = 0; n < tokens.Length;)
            {
                var tok = tokens[n];
                if (tok.Name == Tokens.Not)
                {
                    Debug.Assert(n + 1 < tokens.Length);
                    uint val = ReadValue <T>(tokens[n + 1]);
                    if (val != 0)
                    {
                        value &= ~val;
                    }
                    n += 2;
                }
                else
                {
                    value |= ReadValue <T>(tokens[n]);
                    n++;
                }
            }

            controlStyle = EnumConverter <T> .ConvertToEnum(value);
        }