A value for ParameterSets. Logic can be applied after the string has been formatted in the PatternEvaluator
Exemplo n.º 1
0
 protected override void SetInternal(string key, ParameterValue value)
 {
     _values[key] = value;
 }
Exemplo n.º 2
0
            public override void Visit(Switch sw, State state)
            {
                var val = sw.Evaluator.GetValue(state.Context);

                if (val.Value == null)
                {
                    if (sw.NullExpression != null)
                    {
                        sw.NullExpression.Accept(this, state);
                    }
                }
                else
                {
                    //Enumeration
                    var enumeration = val.Value as IEnumerable;
                    if (enumeration != null && !(enumeration is string)) //We don't want to enumerate the chars in a string
                    {
                        var vals       = enumeration.Cast <object>().ToArray();
                        int iBackwards = -vals.Length;
                        for (int i = 0; i < vals.Length; i++)
                        {
                            state.Values.PushLayer();

                            //The parameter '#Index' provides the current index (1-indexed)
                            state.Values["#Index"] = ParameterValue.Wrap(i + 1);
                            //The parameter '#' here provides the enumerable's current value

                            var pval = vals[i] as ParameterValue;
                            if (pval == null)
                            {
                                //If the item of the enumerable is not a parameter value a clone is created to preserve wrapping, default format etc.
                                pval       = val.Clone();
                                pval.Value = vals[i];
                            }
                            else
                            {
                                pval = ParameterValue.Wrap(vals[i]);
                            }

                            pval.DefaultFormat = pval.DefaultFormat ?? val.DefaultFormat;


                            if (sw.Formatter != null)
                            {
                                state.Values["#"] = new UnencodedParameterValue(GetParameterValue(pval, sw.Formatter, state));
                            }
                            else
                            {
                                state.Values["#"] = pval;
                            }

                            foreach (var sc in sw.Cases)
                            {
                                if (sc.Evaluator.Evaluate(ParameterValue.Wrap(i), state.Context) || sc.Evaluator.Evaluate(ParameterValue.Wrap(iBackwards), state.Context))
                                {
                                    sc.Expression.Accept(this, state);
                                    break;
                                }
                            }

                            state.Values.PopLayer();
                            ++iBackwards;
                        }
                    }
                    else
                    {
                        //The parameter '#' is shorthand for 'evaluated value' in switches. If a format is specified for the switch parameter this is applied
                        state.Values.PushLayer();

                        state.Values["#"] = sw.Formatter != null ?
                                            new UnencodedParameterValue(GetParameterValue(val, sw.Formatter, state)) :
                                            val;

                        foreach (var sc in sw.Cases)
                        {
                            if (sc.Evaluator.Evaluate(val, state.Context))
                            {
                                sc.Expression.Accept(this, state);
                                break;
                            }
                        }
                        state.Values.PopLayer();
                    }
                }


                //Dont' visit cases individually. They are all handled in this method: base.Visit(sw, state);
            }
Exemplo n.º 3
0
 protected abstract void SetInternal(string key, ParameterValue value);
Exemplo n.º 4
0
 protected override void SetInternal(string key, ParameterValue value)
 {
     _layers[_layers.Count - 1][key] = value;
 }