Exemplo n.º 1
0
        private static Query <T> BuildNotQuery <T>(string methodName, QueryBuilderExpression <T, string> queryBuilderExpression, string other)
        {
            var expression = CreateExpression(methodName, queryBuilderExpression, other);
            var lambda     = Expression.Lambda <Func <T, bool> >(Expression.Not(expression), queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }
        private static Query <T> BuildQuery <T>(ConstantExpression otherEntity, QueryBuilderExpression <T, bool> queryBuilderExpression)
        {
            var expression = Expression.Equal(queryBuilderExpression._expression.Body, otherEntity);
            var lambda     = Expression.Lambda <Func <T, bool> >(expression, queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }
        /// <summary>
        /// The property contains at least one value.
        /// </summary>
        /// <typeparam name="T">The type of object the Query is defined against.</typeparam>
        /// <typeparam name="TEnumerable">The enumerable type (to support types inheriting IEnumerable).</typeparam>
        /// <typeparam name="T1">The type of the enumerable</typeparam>
        /// <param name="queryBuilderExpression">The Query.</param>
        /// <returns>True if the property contains at least one value, false otherwise.</returns>
        public static Query <T> NotEmpty <T, TEnumerable, T1>(this QueryBuilderExpression <T, TEnumerable> queryBuilderExpression) where TEnumerable : IEnumerable <T1>
        {
            var method     = typeof(Enumerable).GetMethods().FirstOrDefault(m => m.Name == "Any" && m.GetParameters().Length == 1)?.MakeGenericMethod(typeof(T1));
            var expression = Expression.Call(method, queryBuilderExpression._expression.Body);
            var lambda     = Expression.Lambda <Func <T, bool> >(expression, queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// The property is not null or empty.
        /// </summary>
        /// <typeparam name="T">The type of object the Query is defined against.</typeparam>
        /// <param name="queryBuilderExpression">The Query.</param>
        /// <returns>True if the property is not null or empty, false otherwise.</returns>
        public static Query <T> NotNullOrEmpty <T>(this QueryBuilderExpression <T, string> queryBuilderExpression)
        {
            var method     = typeof(string).GetMethod("IsNullOrEmpty", BindingFlags.Public | BindingFlags.Static);
            var expression = Expression.Call(method, queryBuilderExpression._expression.Body);
            var lambda     = Expression.Lambda <Func <T, bool> >(Expression.Not(expression), queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }
        /// <summary>
        /// The property does not contain the same values in the same order as the supplied enumerable.
        /// </summary>
        /// <typeparam name="T">The type of object the Query is defined against.</typeparam>
        /// <typeparam name="TEnumerable">The enumerable type (to support types inheriting IEnumerable).</typeparam>
        /// <typeparam name="T1">The type of the enumerable</typeparam>
        /// <param name="queryBuilderExpression">The Query.</param>
        /// <param name="other">The enumerable to compare the property to.</param>
        /// <returns>True if the property does not contain the same elements in the same order as the supplied enumerable, false otherwise</returns>
        public static Query <T> NotEqualToSequence <T, TEnumerable, T1>(this QueryBuilderExpression <T, TEnumerable> queryBuilderExpression, IEnumerable <T1> other) where TEnumerable : IEnumerable <T1>
        {
            var otherEntity = Expression.Constant(other, typeof(IEnumerable <T1>));
            var method      = typeof(Enumerable).GetMethods().FirstOrDefault(m => m.Name == "SequenceEqual" && m.GetParameters().Length == 2)?.MakeGenericMethod(typeof(T1));
            var expression  = Expression.Call(method, queryBuilderExpression._expression.Body, otherEntity);
            var lambda      = Expression.Lambda <Func <T, bool> >(Expression.Not(expression), queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }
        /// <summary>
        /// The property has at least one value not satisfying the supplied function.
        /// </summary>
        /// <typeparam name="T">The type of object the Query is defined against.</typeparam>
        /// <typeparam name="TEnumerable">The enumerable type (to support types inheriting IEnumerable).</typeparam>
        /// <typeparam name="T1">The type of the enumerable</typeparam>
        /// <param name="queryBuilderExpression">The Query.</param>
        /// <param name="func">The function to test the values of the enumerable property against.</param>
        /// <returns>True if the property contains at least one value that does not satisfy the supplied function. false otherwise.</returns>
        public static Query <T> WithNotAll <T, TEnumerable, T1>(this QueryBuilderExpression <T, TEnumerable> queryBuilderExpression, Expression <Func <T1, bool> > func) where TEnumerable : IEnumerable <T1>
        {
            var convertToQueryable  = typeof(Queryable).GetMethods().FirstOrDefault(m => m.Name == "AsQueryable" && m.GetParameters().Length == 1)?.MakeGenericMethod(typeof(T1));
            var queryableExpression = Expression.Call(convertToQueryable, queryBuilderExpression._expression.Body);
            var method     = typeof(Queryable).GetMethods().FirstOrDefault(m => m.Name == "All" && m.GetParameters().Length == 2)?.MakeGenericMethod(typeof(T1));
            var expression = Expression.Call(method, queryableExpression, func);
            var lambda     = Expression.Lambda <Func <T, bool> >(Expression.Not(expression), queryBuilderExpression._expression.Parameters);

            return(queryBuilderExpression._continueWith(new Query <T>(lambda)));
        }