/// <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 }
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; }
/// <summary> /// Adds a local <see cref="TemplateFunction"/> to the context under the supplied name, /// overriding any existing <see cref="TemplateFunction"/> with the same name /// </summary> public void SetLocalFunction(string name, TemplateFunction function) { if (_localFunctions == null) { _localFunctions = new FunctionsDictionary(); } _localFunctions[name] = function; }
/// <summary> /// Creates a list of Commands from the temp file /// </summary> /// <param name="filePath"></param> private void CreateCommandList(string filePath) { commands.Clear(); commands.Add(new MacroCommand()); using (StreamReader sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { Command newCommand; var line = sr.ReadLine(); if (line.ElementAt(0) != 'B') { ArgStruct args = ParseLine(line); newCommand = FunctionsDictionary[args._command](args); } else { newCommand = CreateMacro(new MacroCommand(), sr); } commands.Add(newCommand); } } }
/// <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; }
public FunctionsDictionary(FunctionsDictionary dic) : base(dic, StringComparer.OrdinalIgnoreCase) { }