Beispiel #1
0
        public static Func <TResult> CreateReferenceGetter <TResult>(
            ReadOnlyCollection <ParameterExpression> parameters, Tree tree, TResult fallback)
            where TResult : class
        {
            var body   = ExpressionCreator.CreateValueBody(typeof(TResult), tree, Fallback(fallback));
            var lambda = Expression.Lambda <Func <TResult> >(body, parameters);

            return(lambda.Compile());
        }
Beispiel #2
0
        public static Func <TResult?> CreateValueGetter <TResult>(
            ReadOnlyCollection <ParameterExpression> parameters, Tree tree)
            where TResult : struct
        {
            var body   = ExpressionCreator.CreateValueBody(typeof(TResult?), tree);
            var lambda = Expression.Lambda <Func <TResult?> >(body, parameters);

            return(lambda.Compile());
        }
Beispiel #3
0
        CreateGetter <TParameter1, TParameter2, TParameter3, TResult>(
            [NotNull] Expression <Func <TParameter1, TParameter2, TParameter3, TResult> > expression,
            TResult fallback)
        {
            var parameters = expression.Parameters;
            var body       = ExpressionCreator.CreateValueBody(typeof(TResult), expression.Body, Fallback(fallback));
            var lambda     = Expression.Lambda <Func <TParameter1, TParameter2, TParameter3, TResult> >(body, parameters);

            return(lambda.Compile());
        }
Beispiel #4
0
        public static Func <TResult> CreateValueGetter <TResult>(
            Expression <Func <TResult> > expression, TResult fallback)
            where TResult : struct
        {
            var parameters = expression.Parameters;
            var body       = ExpressionCreator.CreateValueBody(typeof(TResult), expression.Body, Fallback(fallback));
            var lambda     = Expression.Lambda <Func <TResult> >(body, parameters);

            return(lambda.Compile());
        }
Beispiel #5
0
        public static Func <TParameter1, TParameter2, TResult> CreateReferenceGetter <TParameter1, TParameter2, TResult>(
            Expression <Func <TParameter1, TParameter2, TResult> > expression)
            where TResult : class
        {
            var parameters = expression.Parameters;
            var body       = ExpressionCreator.CreateValueBody(typeof(TResult), expression.Body);
            var lambda     = Expression.Lambda <Func <TParameter1, TParameter2, TResult> >(body, parameters);

            return(lambda.Compile());
        }
        public static Func <TResult?> CreateValueGetter <TResult>([NotNull] Expression <Func <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 <TResult?> >(body, parameters);

            return(lambda.Compile());
        }
Beispiel #7
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());
        }
Beispiel #8
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());
        }