private ExpressionValue ParseLiteralNode(LiteralNode literalNode)
        {
            switch (literalNode.GetQValueType())
            {
            case QValueType.Boolean:
                return(new ExpressionBool(new string[0], () => QValueTypeParser.ParseBoolean(literalNode.Value)));

            case QValueType.Integer:
                return(new ExpressionInt(new string[0], () => QValueTypeParser.ParseInteger(literalNode.Value)));

            case QValueType.Double:
            case QValueType.Money:
                return(new ExpressionDouble(new string[0], () => QValueTypeParser.ParseDouble(literalNode.Value)));

            case QValueType.Text:
                return(new ExpressionText(new string[0], () => QValueTypeParser.ParseText(literalNode.Value)));

            case QValueType.Hex:
                return(new ExpressionHex(new string[0], () => QValueTypeParser.ParseHexadecimal(literalNode.Value)));

            default:
                throw new NotImplementedException();
            }
        }
示例#2
0
        public void ParseStyle(QLSStyle qlsStyle, out string[] errors)
        {
            List <string>  collectedErrors = new List <string>();
            ColorConverter colorConverter  = new ColorConverter();

            foreach (QLSValue qlsValue in qlsStyle.GetStylingValues())
            {
                if (_supportedStyleProperties.ContainsKey(qlsValue.StyleProperty) && qlsValue.QValueType == _supportedStyleProperties[qlsValue.StyleProperty].Item2)
                {
                    try
                    {
                        StyleProperty styleProperty = _supportedStyleProperties[qlsValue.StyleProperty].Item1;
                        switch (styleProperty)
                        {
                        case StyleProperty.Height:
                            Height = QValueTypeParser.ParseInteger(qlsValue.StyleValue);
                            break;

                        case StyleProperty.Width:
                            Width = QValueTypeParser.ParseInteger(qlsValue.StyleValue);
                            break;

                        case StyleProperty.MarginTop:
                            MarginTop = QValueTypeParser.ParseInteger(qlsValue.StyleValue);
                            break;

                        case StyleProperty.MarginBottom:
                            MarginBottom = QValueTypeParser.ParseInteger(qlsValue.StyleValue);
                            break;

                        case StyleProperty.BackgroundColor:
                            BackgroundColor = QValueTypeParser.ParseHexadecimal(qlsValue.StyleValue).ToColor();
                            break;

                        case StyleProperty.Font:
                            Font = QValueTypeParser.ParseText(qlsValue.StyleValue);
                            break;

                        case StyleProperty.FontSize:
                            FontSize = QValueTypeParser.ParseInteger(qlsValue.StyleValue);
                            break;

                        case StyleProperty.TextColor:
                            TextColor = QValueTypeParser.ParseHexadecimal(qlsValue.StyleValue).ToColor();
                            break;

                        case StyleProperty.AutoSize:
                            AutoSize = QValueTypeParser.ParseBoolean(qlsValue.StyleValue);
                            break;
                        }
                    }
                    catch (InvalidOperationException invalidOperation)
                    {
                        // Exception created by the parser, if parsing fails, the default value is still used
                        // Send the exception message back with the results
                        collectedErrors.Add(invalidOperation.Message);
                    }
                }
                else
                {
                    collectedErrors.Add(UserMessages.UnsupportedStyle(qlsValue.StyleValue, qlsValue.StyleProperty.ToString(), "Windows"));
                }
            }
            errors = collectedErrors.ToArray();
        }