Пример #1
0
        internal Lambda(Expression expression, ParserArguments parserArguments)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }
            if (parserArguments == null)
            {
                throw new ArgumentNullException("parserArguments");
            }

            _expression      = expression;
            _parserArguments = parserArguments;

            // Note: I always compile the generic lambda. Maybe in the future this can be a setting because if I generate a typed delegate this compilation is not required.
            var lambdaExpression = Expression.Lambda(_expression, _parserArguments.UsedParameters.Select(p => p.Expression).ToArray());

            _delegate = lambdaExpression.Compile();
        }
Пример #2
0
        private Lambda ParseAsLambda(string expressionText, Type expressionType, Parameter[] parameters)
        {
            var arguments = new ParserArguments(
                expressionText,
                _settings,
                expressionType,
                parameters);

            var expression = Parser.Parse(arguments);

            foreach (var visitor in Visitors)
            {
                expression = visitor.Visit(expression);
            }

            var lambda = new Lambda(expression, arguments);

#if TEST_DetectIdentifiers
            AssertDetectIdentifiers(lambda);
#endif

            return(lambda);
        }