Exemplo n.º 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);
        }
Exemplo n.º 2
0
 static uint ReadValue <T>(Token tok) where T : struct, IConvertible
 {
     if (tok.Name == Tokens.Ident)
     {
         T style;
         if (Enum.TryParse(tok.Text, out style))
         {
             return(EnumConverter <T> .ConvertFromEnum(style));
         }
         else
         {
             Debug.WriteLine($"Unknown style: {tok.Text}");
             return(0);
         }
     }
     else if (tok.Name == Tokens.Integer)
     {
         uint style;
         if (uint.TryParse(tok.Text, out style))
         {
             return(style);
         }
         Debug.WriteLine($"Unable to parse: {tok.Text}");
         return(0);
     }
     else
     {
         Debug.Assert(false);
         return(0);
     }
 }