Ejemplo n.º 1
0
        public Func <TInput, TOutput> Build(string expression)
        {
            var apriories = AprioriTypesMap.Empty;
            var inputsMap = FluentApiTools.SetupAprioriInputs <TInput>(apriories);

            var outputConverter = FunnyTypeConverters.GetOutputConverter(typeof(TOutput));

            apriories.Add(Parser.AnonymousEquationId, outputConverter.FunnyType);
            var runtime = _builder.CreateRuntime(expression, apriories);

            FluentApiTools.ThrowIfHasUnknownInputs(runtime, inputsMap);

            if (!runtime.HasDefaultOutput)
            {
                throw ErrorFactory.OutputIsUnset(outputConverter.FunnyType);
            }
            var outVariable = runtime.GetVariable(Parser.AnonymousEquationId);


            return(input =>
            {
                var inputValues = FluentApiTools.GetInputValues(inputsMap, input);
                runtime.CalculateSafe(inputValues);
                return (TOutput)outputConverter.ToClrObject(outVariable.FunnyValue);
            });
        }
Ejemplo n.º 2
0
        public Func <TInput, TOutput> Build(string expression)
        {
            var apriories = AprioriTypesMap.Empty;
            var inputsMap = FluentApiTools.SetupAprioriInputs <TInput>(apriories);
            var outputs   = FluentApiTools.SetupManyAprioriOutputs <TOutput>(apriories);
            var runtime   = _builder.CreateRuntime(expression, apriories);

            FluentApiTools.ThrowIfHasUnknownInputs(runtime, inputsMap);
            return(input =>
            {
                var inputValues = FluentApiTools.GetInputValues(inputsMap, input);
                var calcResults = runtime.CalculateSafe(inputValues);
                return FluentApiTools.CreateOutputValueFromResults <TOutput>(outputs, calcResults);
            });
        }
Ejemplo n.º 3
0
        public Func <TInput, object> Build(string expression)
        {
            var apriories = AprioriTypesMap.Empty;
            var inputsMap = FluentApiTools.SetupAprioriInputs <TInput>(apriories);

            var runtime = _builder.CreateRuntime(expression, apriories);

            if (!runtime.HasDefaultOutput)
            {
                throw ErrorFactory.OutputIsUnset();
            }
            FluentApiTools.ThrowIfHasUnknownInputs(runtime, inputsMap);

            return(input =>
            {
                var inputVals = FluentApiTools.GetInputValues(inputsMap, input);
                var result = runtime.CalculateSafe(inputVals);
                return FluentApiTools.GetClrOut(result);
            });
        }