예제 #1
0
        /// <summary>
        /// Constructs a lambda expression that accepts two parameters of type <typeparamref name="T"/> and applies
        /// the specified binary comparison and returns the boolean result.
        /// </summary>
        public static Expression <Func <T, T, bool> > MakeBinaryComparisonLambda <T>(ExpressionType type)
        {
            if (!type.IsBinaryComparison())
            {
                throw new ArgumentException($"Provided ExpressionType '{type}' is not a binary comparison.");
            }

            var left   = Expression.Parameter(typeof(T), "left");
            var right  = Expression.Parameter(typeof(T), "right");
            var body   = Expression.MakeBinary(type, left, right);
            var lambda = Expression.Lambda <Func <T, T, bool> >(body, left, right);

            return(lambda);
        }