public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            rightExpr = Expression.Convert(rightExpr, _type);
            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
            case TableFilterCompareOperator.Equals:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.IsNotNull:
            case TableFilterCompareOperator.NotEquals:
                return(Expression.NotEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThan:
                return(Expression.GreaterThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThanOrEquals:
                return(Expression.GreaterThanOrEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThan:
                return(Expression.LessThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThanOrEquals:
                return(Expression.LessThanOrEqual(leftExpr, rightExpr));
            }
            throw new InvalidOperationException();
        }
示例#2
0
        public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            leftExpr  = RemoveMilliseconds(leftExpr);
            rightExpr = RemoveMilliseconds(rightExpr);
            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
            case TableFilterCompareOperator.Equals:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.IsNotNull:
            case TableFilterCompareOperator.NotEquals:
                return(Expression.NotEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThan:
                return(Expression.GreaterThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThanOrEquals:
                return(Expression.GreaterThanOrEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThan:
                return(Expression.LessThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThanOrEquals:
                return(Expression.LessThanOrEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.TheSameDateWith:
                return(Expression.Equal(Expression.Property(leftExpr, "Date"),
                                        Expression.Property(rightExpr, "Date")));
            }
            throw new InvalidOperationException();
        }
        private Expression GetCaseInsensitiveСomparation(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            MethodInfo           miLower        = typeof(string).GetMethod("ToLower", Array.Empty <Type>());
            Expression           notNull        = Expression.NotEqual(leftExpr, Expression.Constant(null));
            MethodCallExpression lowerLeftExpr  = Expression.Call(leftExpr, miLower);
            MethodCallExpression lowerRightExpr = Expression.Call(rightExpr, miLower);

            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.Equals:
                return(Expression.AndAlso(notNull, Expression.Equal(lowerLeftExpr, lowerRightExpr)));

            case TableFilterCompareOperator.IsNotNull:
                return(Expression.NotEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.NotEquals:
                return(Expression.AndAlso(notNull, Expression.NotEqual(lowerLeftExpr, lowerRightExpr)));

            default:
                string     methodName = Enum.GetName(typeof(TableFilterCompareOperator), compareOperator);
                MethodInfo mi         = typeof(string).GetMethod(methodName, new[] { typeof(string) });
                if (mi == null)
                {
                    throw new MissingMethodException("There is no method - " + methodName);
                }
                return(Expression.AndAlso(notNull, Expression.Call(lowerLeftExpr, mi, lowerRightExpr)));
            }
        }
示例#4
0
 public TableFilter(string text, object value, bool selected, TableFilterCompareOperator filterCompareOperator, TableFilterCondition filterCondition)
 {
     this.Text     = text;
     this.Value    = value;
     this.Selected = selected;
     this.FilterCompareOperator = filterCompareOperator;
     this.FilterCondition       = filterCondition;
 }
示例#5
0
        public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
            case TableFilterCompareOperator.Equals:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.IsNotNull:
            case TableFilterCompareOperator.NotEquals:
                return(Expression.NotEqual(leftExpr, rightExpr));

            default:
                throw new InvalidOperationException($"The compare operator {compareOperator} is not supported for Guid type.");
            }
        }
        public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
            case TableFilterCompareOperator.Equals:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.IsNotNull:
            case TableFilterCompareOperator.NotEquals:
                return(Expression.NotEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.Contains:
            {
                MethodInfo mi = typeof(Enum).GetMethod(nameof(Enum.HasFlag));
                if (leftExpr.Type.IsGenericType)
                {
                    Expression notNull = Expression.NotEqual(leftExpr, Expression.Constant(null));
                    leftExpr  = Expression.MakeMemberAccess(leftExpr, leftExpr.Type.GetMember("Value")[0]);
                    rightExpr = Expression.MakeMemberAccess(rightExpr, rightExpr.Type.GetMember("Value")[0]);
                    rightExpr = Expression.Convert(rightExpr, typeof(Enum));
                    return(Expression.AndAlso(notNull, Expression.Call(leftExpr, mi, rightExpr)));
                }
                rightExpr = Expression.Convert(rightExpr, typeof(Enum));
                return(Expression.Call(leftExpr, mi, rightExpr));
            }

            case TableFilterCompareOperator.NotContains:
            {
                MethodInfo mi = typeof(Enum).GetMethod(nameof(Enum.HasFlag));
                if (leftExpr.Type.IsGenericType)
                {
                    Expression notNull = Expression.NotEqual(leftExpr, Expression.Constant(null));
                    leftExpr  = Expression.MakeMemberAccess(leftExpr, leftExpr.Type.GetMember("Value")[0]);
                    rightExpr = Expression.MakeMemberAccess(rightExpr, rightExpr.Type.GetMember("Value")[0]);
                    rightExpr = Expression.Convert(rightExpr, typeof(Enum));
                    return(Expression.Equal(Expression.AndAlso(notNull, Expression.Call(leftExpr, mi, rightExpr)), Expression.Constant(false, typeof(bool))));
                }
                rightExpr = Expression.Convert(rightExpr, typeof(Enum));
                return(Expression.Equal(Expression.Call(leftExpr, mi, rightExpr), Expression.Constant(false, typeof(bool))));
            }
            }
            throw new InvalidOperationException();
        }
 public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
 {
     return(GetCaseInsensitiveСomparation(compareOperator, leftExpr, rightExpr));
 }
示例#8
0
        public Expression GetFilterExpression(TableFilterCompareOperator compareOperator, Expression leftExpr, Expression rightExpr)
        {
            switch (compareOperator)
            {
            case TableFilterCompareOperator.IsNull:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.IsNotNull:
                return(Expression.NotEqual(leftExpr, rightExpr));
            }

            if (leftExpr.Type.IsGenericType)
            {
                Expression notNull = Expression.NotEqual(leftExpr, Expression.Constant(null));
                Expression isNull  = Expression.Equal(leftExpr, Expression.Constant(null));
                leftExpr  = Expression.Property(leftExpr, "Value");
                rightExpr = Expression.Property(rightExpr, "Value");
                if (compareOperator != TableFilterCompareOperator.TheSameDateWith)
                {
                    leftExpr = RemoveMilliseconds(leftExpr);
                }

                switch (compareOperator)
                {
                case TableFilterCompareOperator.Equals:
                    return(Expression.AndAlso(notNull, Expression.Equal(leftExpr, rightExpr)));

                case TableFilterCompareOperator.NotEquals:
                    return(Expression.OrElse(isNull, Expression.NotEqual(leftExpr, rightExpr)));

                case TableFilterCompareOperator.GreaterThan:
                    return(Expression.AndAlso(notNull, Expression.GreaterThan(leftExpr, rightExpr)));

                case TableFilterCompareOperator.GreaterThanOrEquals:
                    return(Expression.AndAlso(notNull, Expression.GreaterThanOrEqual(leftExpr, rightExpr)));

                case TableFilterCompareOperator.LessThan:
                    return(Expression.AndAlso(notNull, Expression.LessThan(leftExpr, rightExpr)));

                case TableFilterCompareOperator.LessThanOrEquals:
                    return(Expression.AndAlso(notNull, Expression.LessThanOrEqual(leftExpr, rightExpr)));

                case TableFilterCompareOperator.TheSameDateWith:
                    return(Expression.AndAlso(notNull,
                                              Expression.Equal(
                                                  Expression.Property(leftExpr, "Date"),
                                                  Expression.Property(rightExpr, "Date"))));
                }
                throw new InvalidOperationException();
            }

            if (compareOperator != TableFilterCompareOperator.TheSameDateWith)
            {
                leftExpr = RemoveMilliseconds(leftExpr);
            }

            switch (compareOperator)
            {
            case TableFilterCompareOperator.Equals:
                return(Expression.Equal(leftExpr, rightExpr));

            case TableFilterCompareOperator.NotEquals:
                return(Expression.NotEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThan:
                return(Expression.GreaterThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.GreaterThanOrEquals:
                return(Expression.GreaterThanOrEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThan:
                return(Expression.LessThan(leftExpr, rightExpr));

            case TableFilterCompareOperator.LessThanOrEquals:
                return(Expression.LessThanOrEqual(leftExpr, rightExpr));

            case TableFilterCompareOperator.TheSameDateWith:
                return(Expression.Equal(
                           Expression.Property(leftExpr, "Date"),
                           Expression.Property(rightExpr, "Date")));
            }
            throw new InvalidOperationException();
        }