示例#1
0
        public Delegate Build()
        {
            if (!resultDataType.HasValue)
                throw new Exception("Please define a result data type for the formula.");

            Func<Dictionary<string, double>, double> formula = engine.Build(formulaText);

            FuncAdapter adapter = new FuncAdapter();
            return adapter.Wrap(parameters, variables => formula(variables));
        }
示例#2
0
        public void TestFuncAdapterWrap()
        {
            FuncAdapter adapter = new FuncAdapter();

            List<ParameterInfo> parameters = new List<ParameterInfo>() {
                new ParameterInfo() { Name = "test1", DataType = DataType.Integer },
                new ParameterInfo() { Name = "test2", DataType = DataType.FloatingPoint }
            };

            Func<Dictionary<string, double>, double> function = (dictionary) => dictionary["test1"] + dictionary["test2"];

            Func<int, double, double> wrappedFunction = (Func<int, double, double>)adapter.Wrap(parameters, function);

            Assert.AreEqual(3.0, wrappedFunction(1, 2.0));
        }
示例#3
0
        public void TestFourArguments()
        {
            FuncAdapter adapater = new FuncAdapter();

            List<ParameterInfo> parameters = new List<ParameterInfo>() {
                new ParameterInfo() { Name = "test1", DataType = DataType.Integer },
                new ParameterInfo() { Name = "test2", DataType = DataType.Integer },
                new ParameterInfo() { Name = "test3", DataType = DataType.Integer },
                new ParameterInfo() { Name = "test4", DataType = DataType.Integer }
            };

            Func<int, int, int, int, double> wrappedFunction = (Func<int, int, int, int, double>)adapater.Wrap(parameters, dictionary => dictionary["test4"]);

            Assert.AreEqual(8.0, wrappedFunction(2, 4, 6, 8));
        }