public static Func <TParameter, TResult?> CreateValueGetter <TParameter, TResult>(
            [NotNull] Expression <Func <TParameter, TResult> > expression)
            where TResult : struct
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var parameters = expression.Parameters;
            var body       = ExpressionCreator.CreateValueBody(typeof(TResult?), expression.Body);
            var lambda     = Expression.Lambda <Func <TParameter, TResult?> >(body, parameters);

            return(lambda.Compile());
        }
示例#2
0
        public static Func <TParameter1, TParameter2, TResult> CreateGetter <TParameter1, TParameter2, TResult>(
            [NotNull] Expression <Func <TParameter1, TParameter2, TResult> > expression,
            TResult fallback)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            var parameters = expression.Parameters;
            var body       = ExpressionCreator.CreateValueBody(typeof(TResult), expression.Body, Fallback(fallback));
            var lambda     = Expression.Lambda <Func <TParameter1, TParameter2, TResult> >(body, parameters);

            return(lambda.Compile());
        }
示例#3
0
        /// <summary>
        /// Creates the getter.
        /// </summary>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="parameters">The parameters.</param>
        /// <param name="expressionTree">The expression tree.</param>
        /// <returns>The Getter.</returns>
        /// <exception cref="ArgumentNullException">
        /// parameters
        /// or
        /// expressionTree is null.
        /// </exception>
        public static Func <TResult> CreateGetter <TResult>(ReadOnlyCollection <ParameterExpression> parameters, IExpressionTree expressionTree)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (expressionTree == null)
            {
                throw new ArgumentNullException(nameof(expressionTree));
            }

            var body   = ExpressionCreator.CreateValueBody(typeof(TResult), expressionTree);
            var lambda = Expression.Lambda <Func <TResult> >(body, parameters);

            return(lambda.Compile());
        }
        public static Func <TParameter1, TParameter2, TResult?> CreateValueGetter <TParameter1, TParameter2, TResult>(
            [NotNull] ReadOnlyCollection <ParameterExpression> parameters,
            [NotNull] IExpressionTree expressionTree)
            where TResult : struct
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (expressionTree == null)
            {
                throw new ArgumentNullException(nameof(expressionTree));
            }

            var body   = ExpressionCreator.CreateValueBody(typeof(TResult?), expressionTree);
            var lambda = Expression.Lambda <Func <TParameter1, TParameter2, TResult?> >(body, parameters);

            return(lambda.Compile());
        }