Пример #1
0
        string Calculate(ContentExpression expression, EvaluationContext context)
        {
            var sx = expression as SymbolExpression;

            if (sx != null)
            {
                string[] innerTokens;
                var      resolvedSymbol = context.ResolveOptional(sx, out innerTokens);
                _missingTokens.AddRange(innerTokens);
                return(resolvedSymbol);
            }

            var fx = expression as FunctionCallExpression;

            if (fx == null)
            {
                throw new NotImplementedException("Unknown expression type: " + expression);
            }

            var argument = Calculate(fx.Argument, context);

            var args = fx.Options.Select(opt => Resolve(opt, context)).ToArray();

            return(BuiltInFunctions.InvokeOrNull(fx.Function, argument, args));
        }
Пример #2
0
        string Calculate(ContentExpression expression, EvaluationContext context)
        {
            var sx = expression as SymbolExpression;

            if (sx != null)
            {
                string[] innerTokens;
                var      resolvedSymbol = context.ResolveOptional(sx, out innerTokens);
                _missingTokens.AddRange(innerTokens);
                return(resolvedSymbol);
            }

            var fx = expression as FunctionCallExpression;

            if (fx == null)
            {
                throw new NotImplementedException("Unknown expression type: " + expression);
            }

            var args = fx.Arguments.Select(a => Calculate(a, context)).ToArray();

            if (args.Any(a => a == null))
            {
                return(null); // If any argument is undefined, we fail the whole shebang
            }
            return(BuiltInFunctions.InvokeOrNull(fx.Function, args));
        }