Beispiel #1
0
        // Replace all mode by ModeExpression instead of TextExpression
        private void ProcessModeNodes(Expression expression)
        {
            if (expression.IsOfType(ExpressionType.Binding) && expression.Has(BindingExpression.MODE))
            {
                TextExpression text = expression.Get <TextExpression>(BindingExpression.MODE);
                if (text != null)
                {
                    BindingMode mode;
                    if (Enum.TryParse(text.Value, true, out mode))
                    {
                        expression.Replace(BindingExpression.MODE, new ModeExpression {
                            Value = mode
                        });
                    }
                    else
                    {
                        BindingPreprocess.Logger.LogError("Invalid value for Mode in binding Expression actual value is {0}", text.Value);
                    }
                }
                else
                {
                    BindingPreprocess.Logger.LogError("Invalid value for Mode in binding expression actual value is of type {0}", expression[BindingExpression.MODE].Type.ToString());
                }
            }

            foreach (Expression child in expression.Attributes.Values)
            {
                ProcessModeNodes(child);
            }
        }
Beispiel #2
0
        public string GetValue(string key)
        {
            TextExpression expr = Get <TextExpression>(key);

            if (expr != null)
            {
                return(expr.Value);
            }
            return(null);
        }
Beispiel #3
0
        public static Expression CreateExpression(ExpressionType type, List <Tuple <string, Expression> > attributes)
        {
            Expression expr = null;

            switch (type)
            {
            case ExpressionType.Binding:
                expr = new BindingExpression();
                break;

            case ExpressionType.Resource:
                expr = new ResourceExpression();
                break;

            case ExpressionType.Translation:
                expr = new TranslationExpression();
                break;

            case ExpressionType.Value:
                expr = new TextExpression();
                break;
            }

            if (expr == null)
            {
                throw new ArgumentOutOfRangeException("type", type, "expecting Binding, Resource, Translation or Value");
            }

            if (attributes != null)
            {
                foreach (Tuple <string, Expression> pair in attributes)
                {
                    if (expr.IsCorrectKey(pair.Item1))
                    {
                        expr.Add(pair.Item1, pair.Item2);
                    }
                    else
                    {
                        throw new CompileException(string.Format("Unexpected attribute with key {0}", pair.Item1));
                    }
                }
            }

            return(expr);
        }
        public static Expression CreateExpression(ExpressionType type, List<Tuple<string, Expression>> attributes)
        {
            Expression expr = null;
            switch (type)
            {
                case ExpressionType.Binding:
                    expr = new BindingExpression();
                    break;
                case ExpressionType.Resource:
                    expr = new ResourceExpression();
                    break;
                case ExpressionType.Translation:
                    expr = new TranslationExpression();
                    break;
                case ExpressionType.Value:
                    expr = new TextExpression();
                    break;
            }

            if (expr == null)
            {
                throw new ArgumentOutOfRangeException("type", type, "expecting Binding, Resource, Translation or Value");
            }

            if (attributes != null)
            {
                foreach (Tuple<string, Expression> pair in attributes)
                {
                    if (expr.IsCorrectKey(pair.Item1))
                    {
                        expr.Add(pair.Item1, pair.Item2);
                    }
                    else
                    {
                        throw new CompileException(string.Format("Unexpected attribute with key {0}", pair.Item1));
                    }
                }
            }

            return expr;
        }