Exemplo n.º 1
0
 /// <summary>
 /// Creates a new instance of the <see cref="EvaluationContext"/> class.
 /// </summary>
 /// <param name="globalFunctions">The global functions of the evaluation context.</param>
 /// <param name="globalVariables">The global variables of the evaluation context.</param>
 /// <returns>A new immutable instance of the evaluation context.</returns>
 public static EvaluationContext Create(FunctionsDictionary globalFunctions,
                                        VariablesDictionary globalVariables)
 {
     return(new EvaluationContext(
                new FunctionsDictionary(globalFunctions),
                new VariablesDictionary(globalVariables))); // Makes them immutable
 }
Exemplo n.º 2
0
 private EvaluationContext(               // Private ctor forces the creation of evaluation context from Create method
     FunctionsDictionary globalFunctions,
     VariablesDictionary globalVariables) // Globals are only created once
 {
     _globalFunctions = globalFunctions;
     _globalVariables = globalVariables;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a local <see cref="TemplateVariable"/> to the context under the supplied name,
        /// overriding any existing <see cref="TemplateVariable"/> with the same name
        /// </summary>
        public void SetLocalVariable(string name, TemplateVariable variable)
        {
            if (_localVariables == null)
            {
                _localVariables = new VariablesDictionary();
            }

            _localVariables[name] = variable;
        }
Exemplo n.º 4
0
 //IStatement
 public void Execute()
 {
     if (!IsObject)
     {
         VariablesDictionary.SetVariable(variable, expression.Evaluate());
     }
     else
     {
         ExecuteArray();
     }
 }
Exemplo n.º 5
0
        private void ExecuteArray()
        {
            IObject obj    = VariablesDictionary.GetObject(variable);
            IObject result = obj;

            GetIndexes();
            for (int i = 0; i < indexes.Count; ++i)
            {
                if (i == indexes.Count - 1)
                {
                    if (obj is ArrayIndex && indexes[i] is int)
                    {
                        ((ArrayIndex)obj)[(int)indexes[i]] = getObject();
                    }
                    else if (obj is ArrayObject && indexes[i] is string)
                    {
                        ((ArrayObject)obj)[(string)indexes[i]] = getObject();
                    }
                    else
                    {
                        throw new Exception("wrong index or type");
                    }
                    break;
                }
                if (obj is ArrayIndex && indexes[i] is int)
                {
                    obj = ((ArrayIndex)obj)[(int)indexes[i]];
                }
                else if (obj is ArrayObject && indexes[i] is string)
                {
                    obj = ((ArrayObject)obj)[(string)indexes[i]];
                }
                else
                {
                    throw new Exception("wrong index or type");
                }
            }
            VariablesDictionary.SetVariable(variable, result);
        }
Exemplo n.º 6
0
 //IStatement
 public void Execute()
 {
     VariablesDictionary.PutVariable(variable, expression.Evaluate());
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EvaluationContext"/> class.
 /// Making it private forces the creation of evaluation context from the
 /// <see cref="Create(FunctionsDictionary, VariablesDictionary)"/> method.
 /// </summary>
 /// <param name="globalFunctions">The global functions of the evaluation context.</param>
 /// <param name="globalVariables">The global variables of the evaluation context.</param>
 private EvaluationContext(FunctionsDictionary globalFunctions, VariablesDictionary globalVariables)
 {
     _globalFunctions = globalFunctions;
     _globalVariables = globalVariables;
 }
Exemplo n.º 8
0
 public VariablesDictionary(VariablesDictionary dic) : base(dic, StringComparer.OrdinalIgnoreCase)
 {
 }
        //default
        private IExpressionData DefaultEvaluate()
        {
            IObject data = VariablesDictionary.GetObject(name);

            return(getVariable(data));
        }