Esempio n. 1
0
        public void TestAddConstant()
        {
            ConstantRegistry registry = new ConstantRegistry(false);

            registry.RegisterConstant("test", 42.0);

            ConstantInfo functionInfo = registry.GetConstantInfo("test");

            Assert.IsNotNull(functionInfo);
            Assert.AreEqual("test", functionInfo.ConstantName);
            Assert.AreEqual(42.0, functionInfo.Value);
        }
Esempio n. 2
0
        /// <summary>
        /// Verify a collection of variables to ensure that all the variable names are valid.
        /// Users are not allowed to overwrite reserved variables or use function names as variables.
        /// If an invalid variable is detected an exception is thrown.
        /// </summary>
        /// <param name="variables">The colletion of variables that must be verified.</param>
        internal void VerifyVariableNames(IDictionary <string, ExecutionResult> variables)
        {
            foreach (string variableName in variables.Keys)
            {
                if (ConstantRegistry.IsConstantName(variableName) && !ConstantRegistry.GetConstantInfo(variableName).IsOverWritable)
                {
                    throw new ArgumentException(string.Format("The name \"{0}\" is a reservered variable name that cannot be overwritten.", variableName), "variables");
                }

                if (FunctionRegistry.IsFunctionName(variableName))
                {
                    throw new ArgumentException(string.Format("The name \"{0}\" is a function name. Parameters cannot have this name.", variableName), "variables");
                }
            }
        }