public static Predicate <object> ParsePredicate([CanBeNull] ParsingConfig parsingConfig, bool createParameterCtor, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values)
 {
     Check.NotNull(itType, nameof(itType));
     Check.NotEmpty(expression, nameof(expression));
     try
     {
         ParameterExpression objParam = System.Linq.Expressions.Expression.Parameter(typeof(object), "x");
         Expression          lambda   = ParseLambdaExpression(parsingConfig, createParameterCtor, itType, new[] { objParam }, resultType, expression, values);
         Expression <Func <object, bool> > equalfunctionNull = System.Linq.Expressions.Expression.Lambda <Func <object, bool> >(lambda, objParam);
         return(new Predicate <object>(equalfunctionNull.Compile()));
     }
     catch
     {
         return(new Predicate <object>((p) => {
             return false;
         }));
     }
 }
Example #2
0
        public KeywordsHelper(ParsingConfig config)
        {
            if (config.AreContextKeywordsEnabled)
            {
                _keywords.Add(KEYWORD_IT, KEYWORD_IT);
                _keywords.Add(KEYWORD_PARENT, KEYWORD_PARENT);
                _keywords.Add(KEYWORD_ROOT, KEYWORD_ROOT);
            }

            _keywords.Add(SYMBOL_IT, SYMBOL_IT);
            _keywords.Add(SYMBOL_PARENT, SYMBOL_PARENT);
            _keywords.Add(SYMBOL_ROOT, SYMBOL_ROOT);
            _keywords.Add(KEYWORD_IIF, KEYWORD_IIF);
            _keywords.Add(KEYWORD_NEW, KEYWORD_NEW);
            _keywords.Add(KEYWORD_ISNULL, KEYWORD_ISNULL);

            foreach (Type type in PredefinedTypesHelper.PredefinedTypes.OrderBy(kvp => kvp.Value).Select(kvp => kvp.Key))
            {
                _keywords[type.FullName] = type;
                _keywords[type.Name]     = type;
            }

            foreach (KeyValuePair <string, Type> pair in PredefinedTypesHelper.PredefinedTypesShorthands)
            {
                _keywords.Add(pair.Key, pair.Value);
            }

            if (config.CustomTypeProvider != null)
            {
                foreach (Type type in config.CustomTypeProvider.GetCustomTypes())
                {
                    _keywords[type.FullName] = type;
                    _keywords[type.Name]     = type;
                }
            }
        }
Example #3
0
 public static Predicate <object> ConvertStringToLambda(Type sourceType, Expression sourceExoression, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args)
 {
     Check.NotEmpty(predicate, nameof(predicate));
     return(DynamicExpressionParser.ParsePredicate(config, sourceType, null, predicate, args));
 }
Example #4
0
        /// <summary>
        /// Filters a sequence of values based on a predicate.
        /// </summary>
        /// <typeparam name="TSource">The type of the elements of source.</typeparam>
        /// <param name="source">A <see cref="IQueryable{TSource}"/> to filter.</param>
        /// <param name="config">The <see cref="ParsingConfig"/>.</param>
        /// <param name="predicate">An expression string to test each element for a condition.</param>
        /// <param name="args">An object array that contains zero or more objects to insert into the predicate as parameters. Similar to the way String.Format formats strings.</param>
        /// <returns>A <see cref="IQueryable{TSource}"/> that contains elements from the input sequence that satisfy the condition specified by predicate.</returns>
        /// <example>
        /// <code language="cs">
        /// var result1 = queryable.Where("NumberProperty = 1");
        /// var result2 = queryable.Where("NumberProperty = @0", 1);
        /// var result3 = queryable.Where("StringProperty = null");
        /// var result4 = queryable.Where("StringProperty = \"abc\"");
        /// var result5 = queryable.Where("StringProperty = @0", "abc");
        /// </code>
        /// </example>
        public static IQueryable <TSource> Where <TSource>([NotNull] this IQueryable <TSource> source, [CanBeNull] ParsingConfig config, [NotNull] string predicate, params object[] args)
        {
            Check.NotNull(source, nameof(source));
            Check.NotEmpty(predicate, nameof(predicate));

            return((IQueryable <TSource>)Where((IQueryable)source, config, predicate, args));
        }
 public static Expression <Func <TResult> > ParseLambda <TResult>([CanBeNull] ParsingConfig parsingConfig, bool createParameterCtor, [NotNull] ParameterExpression[] parameters, [NotNull] string expression, params object[] values)
 {
     return((Expression <Func <TResult> >)ParseLambda(parsingConfig, createParameterCtor, parameters, typeof(TResult), expression, values));
 }
 public static LambdaExpression ParseLambda([CanBeNull] ParsingConfig parsingConfig, [NotNull] ParameterExpression[] parameters, [CanBeNull] Type resultType, string expression, params object[] values)
 {
     return(ParseLambda(parsingConfig, true, parameters, resultType, expression, values));
 }
 public static Predicate <object> ParsePredicate([CanBeNull] ParsingConfig parsingConfig, [NotNull] Type itType, [CanBeNull] Type resultType, string expression, params object[] values)
 {
     return(ParsePredicate(parsingConfig, true, itType, resultType, expression, values));
 }
        public static Expression <Func <T, TResult> > ParseLambda <T, TResult>([CanBeNull] ParsingConfig parsingConfig, bool createParameterCtor, [NotNull] string expression, params object[] values)
        {
            Check.NotEmpty(expression, nameof(expression));

            return((Expression <Func <T, TResult> >)ParseLambda(parsingConfig, createParameterCtor, new[] { ParameterExpressionHelper.CreateParameterExpression(typeof(T), string.Empty) }, typeof(TResult), expression, values));
        }