public static IQueryable OrderBy(this IQueryable source, string ordering, QueryResolver queryResolver)
 {
     if (source == null)
         throw new ArgumentNullException("source");
     if (ordering == null)
         throw new ArgumentNullException("ordering");
     ParameterExpression[] parameters = new ParameterExpression[] {
         Expression.Parameter(source.ElementType, "") };
     ExpressionParser parser = new ExpressionParser(parameters, ordering, queryResolver);
     IEnumerable<DynamicOrdering> orderings = parser.ParseOrdering();
     Expression queryExpr = source.Expression;
     string methodAsc = "OrderBy";
     string methodDesc = "OrderByDescending";
     foreach (DynamicOrdering o in orderings)
     {
         queryExpr = Expression.Call(
             typeof(Queryable), o.Ascending ? methodAsc : methodDesc,
             new Type[] { source.ElementType, o.Selector.Type },
             queryExpr, Expression.Quote(DynamicExpression.Lambda(o.Selector, parameters)));
         methodAsc = "ThenBy";
         methodDesc = "ThenByDescending";
     }
     return source.Provider.CreateQuery(queryExpr);
 }
Esempio n. 2
0
 /// <summary>
 /// Evaluate a string expression to a boolean "True" or "False" (if possible).
 /// An alternative to Evaluate that behaves nicely with the TextWindow.
 /// </summary>
 /// <param name="expression">The expression to evaluate to a boolean, e.g. "21.3 > 16".</param>
 /// <returns>The evaluated result ("True" or "False").</returns>
 public static Primitive Evaluate3(Primitive expression)
 {
     try
     {
         ParameterExpression pe = Expression.Parameter(typeof(string), "IntegerAsReal");
         ExpressionParser parser = new ExpressionParser(new ParameterExpression[] { pe }, expression, null);
         LambdaExpression expr = Expression.Lambda(parser.Parse(typeof(bool)), null);
         var del = (Func<bool>)expr.Compile();
         return del();
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
         return "";
     }
 }
Esempio n. 3
0
        public static LambdaExpression ParseLambda(IDynamicLinkCustomTypeProvider provider, ParameterExpression[] parameters, Type resultType, string expression, params object[] values)
        {
            ExpressionParser parser = new ExpressionParser(provider, parameters, expression, values);

            return(Expression.Lambda(parser.Parse(resultType), parameters));
        }
Esempio n. 4
0
        public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, params object[] values)
        {
            ExpressionParser parser = new ExpressionParser(parameters, expression, values);

            return(Expression.Lambda(parser.Parse(resultType), parameters));
        }
        public static Expression Parse(Type resultType, string expression, params object[] values)
        {
            var parser = new ExpressionParser(null, expression, values);

            return(parser.Parse(resultType));
        }
Esempio n. 6
0
		private void ValidateToken(ExpressionParser.TokenId t)
		{
			if (this.token.id != t)
			{
				throw this.ParseError("Syntax error", new object[0]);
			}
		}
Esempio n. 7
0
		private void ValidateToken(ExpressionParser.TokenId t, string errorMessage)
		{
			if (this.token.id != t)
			{
				throw this.ParseError(errorMessage, new object[0]);
			}
		}
Esempio n. 8
0
		private static bool IsBetterThan(Expression[] args, ExpressionParser.MethodData m1, ExpressionParser.MethodData m2)
		{
			bool result = false;
			for (int i = 0; i < args.Length; i++)
			{
				int num = ExpressionParser.CompareConversions(args[i].Type, m1.Parameters[i].ParameterType, m2.Parameters[i].ParameterType);
				if (num < 0)
				{
					return false;
				}
				if (num > 0)
				{
					result = true;
				}
			}
			return result;
		}
Esempio n. 9
0
		private bool IsApplicable(ExpressionParser.MethodData method, Expression[] args)
		{
			if (method.Parameters.Length != args.Length)
			{
				return false;
			}
			Expression[] array = new Expression[args.Length];
			for (int i = 0; i < args.Length; i++)
			{
				ParameterInfo parameterInfo = method.Parameters[i];
				if (parameterInfo.IsOut)
				{
					return false;
				}
				Expression expression = this.PromoteExpression(args[i], parameterInfo.ParameterType, false);
				if (expression == null)
				{
					return false;
				}
				array[i] = expression;
			}
			method.Args = array;
			return true;
		}
 public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, params object[] values)
 {
     ExpressionParser parser = new ExpressionParser(parameters, expression, values);
     return Expression.Lambda(parser.Parse(resultType), parameters);
 }
Esempio n. 11
0
            protected override Expression VisitMember(MemberExpression m)
            {
                if (!this.isInProjection)
                {
                    if (m.Member.MemberType == MemberTypes.Property)
                    {
                        PropertyDescriptor pd = TypeDescriptor.GetProperties(m.Member.DeclaringType)[m.Member.Name];

                        // Let properties for which no PropertyDescriptors exist go through. This happens when we
                        // deal with structs.
                        bool requiresValidation = !(pd == null && m.Member.DeclaringType.IsValueType);
                        if (requiresValidation && !this.IsVisible(pd))
                        {
                            if (!PostProcessor.IsProjectionPath(m))
                            {
                                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.UnknownPropertyOrField, pd.Name, ExpressionParser.GetTypeName(pd.ComponentType)));
                            }
                            else
                            {
                                this.isInProjection = true;
                                Expression expr = base.VisitMember(m);
                                this.isInProjection = false;
                                return(expr);
                            }
                        }
                    }
                }

                return(base.VisitMember(m));
            }
Esempio n. 12
0
        public static Expression Parse(Type resultType, string expression, ICollection <Type> additionalAllowedTypes = null, params object[] values)
        {
            var parser = new ExpressionParser(null, expression, values, additionalAllowedTypes);

            return(parser.Parse(resultType));
        }
Esempio n. 13
0
        public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, ICollection <Type> additionalAllowedTypes = null, params object[] values)
        {
            var parser = new ExpressionParser(parameters, expression, values, additionalAllowedTypes);

            return(Expression.Lambda(parser.Parse(resultType), parameters));
        }
 public static LambdaExpression ParseLambda(ParameterExpression[] parameters, Type resultType, string expression, QueryResolver queryResolver)
 {
     ExpressionParser parser = new ExpressionParser(parameters, expression, queryResolver);
     return Lambda(parser.Parse(resultType), parameters);
 }