System.Linq.Dynamic.ExpressionParser.Parse C# (CSharp) Method

Parse() public method

public Parse ( Type resultType ) : Expression
resultType Type
return Expression
		public Expression Parse(Type resultType)
		{
			int exprPos = _token.Position;
			Expression expr = ParseExpression();
			if (resultType != null)
			{
				expr = PromoteExpression(expr, resultType, true);
				if (expr == null)
				{
					throw ParseError(exprPos, Res.ExpressionTypeMismatch(GetTypeName(resultType)));
				}
			}
			ValidateToken(TokenId.End, Res.SyntaxError);
			return expr;
		}

Usage Example

Beispiel #1
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 "";
     }
 }
All Usage Examples Of System.Linq.Dynamic.ExpressionParser::Parse
ExpressionParser