示例#1
0
        public Expression <Func <T, bool> > GreaterOrEqualComparator <T>(ParameterExpression parameter, RsqlParser.ComparisonContext context)
        {
            parameter = parameter ?? throw new ArgumentNullException(nameof(parameter));
            context   = context ?? throw new ArgumentNullException(nameof(context));

            var expressionPath = this._propertyAccessor.ParsePath(parameter, context.selector().GetText());

            this.EnsureComparable(expressionPath.Type, context);

            var value = ComparisonBuilder.GetSingleValue(expressionPath.Type, context);

            return(Expression.Lambda <Func <T, bool> >(
                       ComparisonBuilder.PathNotNull(
                           expressionPath,
                           Expression.GreaterThanOrEqual(
                               expressionPath.Expression,
                               Expression.Constant(value, expressionPath.Type))),
                       parameter));
        }
示例#2
0
        public Expression <Func <T, bool> > InComparator <T>(ParameterExpression parameter, RsqlParser.ComparisonContext context)
        {
            parameter = parameter ?? throw new ArgumentNullException(nameof(parameter));
            context   = context ?? throw new ArgumentNullException(nameof(context));

            var expressionPath = this._propertyAccessor.ParsePath(parameter, context.selector().GetText());

            this.EnsureEquatable(expressionPath.Type, context);

            var values             = ValueParser.GetValues(expressionPath.Type, context.arguments());
            var methodContainsInfo = ContainsHelper.GetOrRegistryContainsMethodInfo(expressionPath.Type);

            return(Expression.Lambda <Func <T, bool> >(
                       ComparisonBuilder.PathNotNull(
                           expressionPath,
                           Expression.Call(
                               Expression.Constant(methodContainsInfo.Convert(values)),
                               methodContainsInfo.ContainsMethod,
                               expressionPath.Expression)),
                       parameter));
        }
示例#3
0
        public Expression <Func <T, bool> > EqualComparator <T>(ParameterExpression parameter, RsqlParser.ComparisonContext context)
        {
            parameter = parameter ?? throw new ArgumentNullException(nameof(parameter));
            context   = context ?? throw new ArgumentNullException(nameof(context));

            var expressionPath = this._propertyAccessor.ParsePath(parameter, context.selector().GetText());

            this.EnsureEquatable(expressionPath.Type, context);

            var value = ComparisonBuilder.GetSingleValue(expressionPath.Type, context);

            if (expressionPath.Type != typeof(string))
            {
                return(Expression.Lambda <Func <T, bool> >(
                           ComparisonBuilder.PathNotNull(
                               expressionPath,
                               Expression.Equal(
                                   expressionPath.Expression,
                                   Expression.Constant(value, expressionPath.Type)
                                   )),
                           parameter));
            }

            var escapedLike = ((string)value).Replace(@"\*", ComparisonBuilder.EscapedLikePlaceholder);

            if (escapedLike.Contains('*'))
            {
                return(this.LikeComparator <T>(parameter, context));
            }

            escapedLike = escapedLike.Replace(ComparisonBuilder.EscapedLikePlaceholder, "*");
            return(Expression.Lambda <Func <T, bool> >(
                       ComparisonBuilder.PathNotNull(
                           expressionPath,
                           Expression.Equal(
                               expressionPath.Expression,
                               Expression.Constant(escapedLike, expressionPath.Type))),
                       parameter));
        }