public override bool BoolEvaluate (IExpressionContext context) { if (left.CanEvaluateToNumber (context) && right.CanEvaluateToNumber (context)) { float l,r; l = left.NumberEvaluate (context); r = right.NumberEvaluate (context); return NumberCompare (l, r, op); } else if (left.CanEvaluateToBool (context) && right.CanEvaluateToBool (context)) { bool l,r; l = left.BoolEvaluate (context); r = right.BoolEvaluate (context); return BoolCompare (l, r, op); } else { string l,r; l = left.StringEvaluate (context); r = right.StringEvaluate (context); return StringCompare (l, r, op); } }
public ValueStack(IExceptionHandler handler, IExpressionContext expressionContext) { Values = new CustomDictionary(); _exceptionHandler = handler; _evaluator = expressionContext.CreateEvaluator(this); Persistables = new Dictionary<string, IPersistable>(); }
public override bool BoolEvaluate (IExpressionContext context) { if (left.BoolEvaluate (context)) return true; if (right.BoolEvaluate (context)) return true; return false; }
public override bool BoolEvaluate (IExpressionContext context) { Token evaluatedToken = EvaluateToken (token, context); if (trueValues [evaluatedToken.Value] != null) return true; else if (falseValues [evaluatedToken.Value] != null) return false; else throw new InvalidOperationException (); }
public static bool ParseAndEvaluate (string condition, IExpressionContext context) { if (String.IsNullOrEmpty (condition)) return true; ConditionExpression ce = ParseCondition (condition); if (!ce.CanEvaluateToBool (context)) throw new Exception (String.Format ("Can not evaluate \"{0}\" to bool.", condition)); return ce.BoolEvaluate (context); }
public override bool BoolEvaluate (IExpressionContext context) { Token evaluatedToken = EvaluateToken (token, context); if (trueValues [evaluatedToken.Value] != null) return true; else if (falseValues [evaluatedToken.Value] != null) return false; else throw new ExpressionEvaluationException ( String.Format ("Expression \"{0}\" evaluated to \"{1}\" instead of a boolean value", token.Value, evaluatedToken.Value)); }
public override bool BoolEvaluate (IExpressionContext context) { Func<string, IExpressionContext, bool> func; if (!functions.TryGetValue (name, out func)) { // MSB4091 throw new Exception (string.Format ("Found a call to an undefined function \"{0}\".", name)); } if (args.Count != 1) { // MSB4089 throw new Exception (string.Format ("Incorrect number of arguments to function in condition \"{0}\". Found {1} argument(s) when expecting {2}.", name, args.Count, 1)); } return func (args [0].StringEvaluate (context), context); }
public override bool BoolEvaluate (IExpressionContext context) { if (!functions.ContainsKey (name)) throw new InvalidOperationException ("Unknown function named: " + name); if (functions [name] == null) throw new InvalidOperationException ("Unknown function named: " + name); MethodInfo mi = functions [name]; object [] argsArr = new object [args.Count + 1]; int i = 0; foreach (ConditionFactorExpression cfe in args) argsArr [i++] = cfe.StringEvaluate (context); argsArr [i] = context; return (bool) mi.Invoke (null, argsArr); }
public static bool ParseAndEvaluate (string condition, IExpressionContext context) { if (String.IsNullOrEmpty (condition)) return true; try { ConditionExpression ce = ParseCondition (condition); if (!ce.CanEvaluateToBool (context)) throw new InvalidProjectFileException (String.Format ("Can not evaluate \"{0}\" to bool.", condition)); return ce.BoolEvaluate (context); } catch (ExpressionParseException epe) { throw new InvalidProjectFileException ( String.Format ("Unable to parse condition \"{0}\" : {1}", condition, epe.Message), epe); } catch (ExpressionEvaluationException epe) { throw new InvalidProjectFileException ( String.Format ("Unable to evaluate condition \"{0}\" : {1}", condition, epe.Message), epe); } }
#pragma warning disable 0169 #region Functions // FIXME imported projects static bool Exists (string file, IExpressionContext context) { if (string.IsNullOrEmpty (file)) return false; string directory = context.FullDirectoryName; file = MSBuildProjectService.FromMSBuildPath (directory, file); bool res; if (context.ExistsEvaluationCache.TryGetValue (file, out res)) return res; res = File.Exists (file) || Directory.Exists (file); context.ExistsEvaluationCache [file] = res; return res; }
public abstract string StringEvaluate(IExpressionContext context);
public static void Init(IExpressionContext context) { Current = context; }
public abstract bool CanEvaluateToString(IExpressionContext context);
/// <summary> /// Gets the member infos for the specified type. /// </summary> /// <param name="context">The expression context.</param> /// <param name="type">The type.</param> /// <returns></returns> protected override IEnumerable <ConstructorInfo> GetMemberInfosForType(IExpressionContext context, Type type) { return(type.GetConstructors()); }
public override bool CanEvaluateToBool(IExpressionContext context) { // Short-circuiting, check only left expr, right // would be required only if left == true return(left.CanEvaluateToBool(context)); }
public static Log Log(this IExpressionContext context) => context.Item <Log>();
public override IExpression Invoke(IExpressionContext context) => Constant.Create(nameof(OmniLog.LogLevel), context.Log().Name());
public override bool CanEvaluateToNumber(IExpressionContext context) { return(false); }
public IEnumerable <MemberInfo> GetMembers(IExpressionContext context) { return(this.Select(m => m.ToMemberInfo(context))); }
// FIXME: check if we really can do it public override bool CanEvaluateToBool(IExpressionContext context) { return(true); }
public override string StringEvaluate(IExpressionContext context) { throw new NotSupportedException(); }
public override float NumberEvaluate(IExpressionContext context) { throw new NotSupportedException(); }
// FIXME: in some situations items might not be allowed static Token EvaluateToken (Token token, IExpressionContext context) { string val = context.EvaluateString (token.Value); return new Token (val, TokenType.String); }
/// <summary> /// Converts this instance to an boolean expression. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="context">The context.</param> /// <returns></returns> public Expression <Func <TEntity, bool> > ToBooleanExpression <TEntity>(IExpressionContext context = null) { return(ToExpression(ConvertToBooleanExpression <TEntity>, context ?? new ExpressionContext())); }
public abstract float NumberEvaluate(IExpressionContext context);
public abstract bool CanEvaluateToBool(IExpressionContext context);
public override bool CanEvaluateToBool (IExpressionContext context) { return expression.CanEvaluateToBool (context); }
public abstract bool CanEvaluateToString (IExpressionContext context);
public override bool CanEvaluateToString (IExpressionContext context) { return false; }
/// <summary> /// Invokes the expression with the specified expression context and /// binding options. /// </summary> /// <param name="expressionContext">The expression context used to /// bind and execute the expression.</param> /// <param name="options">The options used to bind the expression.</param> /// <returns>The result of the expression.</returns> public object Invoke(IExpressionContext expressionContext, BoundExpressionOptions options) { if (expressionContext == null) expressionContext = new ExpressionContext(); return Bind(expressionContext, options).Invoke(expressionContext); }
/// <summary> /// Converts this instance to an expression. /// </summary> /// <typeparam name="TDelegate">The type of the delegate.</typeparam> /// <param name="conversionFunction">The conversion function.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException"> /// Parameter <paramref name="conversionFunction"/> or <paramref name="context"/> is null. /// </exception> public Expression <TDelegate> ToExpression <TDelegate>(Func <ExpressionNode, IExpressionContext, Expression <TDelegate> > conversionFunction, IExpressionContext context) { if (conversionFunction == null) { throw new ArgumentNullException(nameof(conversionFunction)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } return(conversionFunction(this, context)); }
public abstract bool CanEvaluateToNumber(IExpressionContext context);
/// <summary> /// Converts to an expression. /// </summary> /// <typeparam name="TDelegate">The type of the delegate.</typeparam> /// <param name="expressionNode">The expression node.</param> /// <param name="context">The context.</param> /// <returns></returns> private static Expression <TDelegate> ConvertToExpression <TDelegate>(ExpressionNode expressionNode, IExpressionContext context) { var expression = expressionNode.ToExpression(context); return((Expression <TDelegate>)expression); }
/// <summary> /// Converts to a boolean expression. /// </summary> /// <typeparam name="TEntity">The type of the entity.</typeparam> /// <param name="expressionNode">The expression node.</param> /// <param name="context">The context.</param> /// <returns></returns> private static Expression <Func <TEntity, bool> > ConvertToBooleanExpression <TEntity>(ExpressionNode expressionNode, IExpressionContext context) { return(ConvertToExpression <Func <TEntity, bool> >(expressionNode, context)); }
/// <summary> /// Invokes the expression with the specified expression context. /// </summary> /// <param name="expressionContext">The expression context used to /// bind and execute the expression.</param> /// <returns>The result of the expression.</returns> public object Invoke(IExpressionContext expressionContext) { return Invoke(expressionContext, null); }
/// <summary> /// Converts this instance to an expression. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public virtual Expression ToExpression(IExpressionContext context) { return(null); }
#pragma warning disable 0169 #region Functions // FIXME imported projects static bool Exists (string file, IExpressionContext context) { if (string.IsNullOrEmpty (file)) return false; string directory = null; if (context.FullFileName != String.Empty) directory = Path.GetDirectoryName (context.FullFileName); file = MSBuildProjectService.FromMSBuildPath (directory, file); return File.Exists (file) || Directory.Exists (file); }
/// <summary> /// Converts this instance to an expression. /// </summary> /// <typeparam name="TDelegate">The type of the delegate.</typeparam> /// <param name="context">The context.</param> /// <returns></returns> public Expression <TDelegate> ToExpression <TDelegate>(IExpressionContext context = null) { return(ToExpression(ConvertToExpression <TDelegate>, context ?? new ExpressionContext())); }
static bool HasTrailingSlash (string file, IExpressionContext context) { if (file == null) return false; file = file.Trim (); int len = file.Length; if (len == 0) return false; return file [len - 1] == '\\' || file [len - 1] == '/'; }
public abstract bool TryEvaluateToBool(IExpressionContext context, out bool result);
public override bool CanEvaluateToBool (IExpressionContext context) { return functions.ContainsKey (name); }
public override float NumberEvaluate (IExpressionContext context) { Token evaluatedToken = EvaluateToken (token, context); return Single.Parse (evaluatedToken.Value, CultureInfo.InvariantCulture); }
public override bool CanEvaluateToNumber (IExpressionContext context) { if (token.Type == TokenType.Number) return true; else return false; }
// FIXME: check if we really can do it public override bool CanEvaluateToBool (IExpressionContext context) { Token evaluatedToken = EvaluateToken (token, context); if (token.Type == TokenType.String && allValues [evaluatedToken.Value] != null) return true; else return false; }
public virtual bool TryEvaluateToNumber(IExpressionContext context, out float result) { result = 0; return(false); }
public abstract bool BoolEvaluate(IExpressionContext context);
public override string StringEvaluate (IExpressionContext context) { Token evaluatedToken = EvaluateToken (token, context); return evaluatedToken.Value; }
public virtual bool TryEvaluateToString(IExpressionContext context, out string result) { result = null; return(false); }
public override bool CanEvaluateToBool (IExpressionContext context) { return left.CanEvaluateToBool (context) && right.CanEvaluateToBool (context); }
public virtual bool TryEvaluateToVersion(IExpressionContext context, out Version result) { result = null; return(false); }
public override bool BoolEvaluate (IExpressionContext context) { return !(expression.BoolEvaluate (context)); }
public override string StringEvaluate (IExpressionContext context) { throw new NotSupportedException (); }
public override System.Linq.Expressions.Expression ToLinqExpression(IExpressionContext ctx) { throw new NotImplementedException(); }
public override float NumberEvaluate (IExpressionContext context) { throw new NotSupportedException (); }
protected override IAggregateFluent <ProductSubgroupView> ConvertToViewAggreagate(IAggregateFluent <ProductSubgroup> mappings, IExpressionContext <ProductSubgroup, ProductSubgroupView> context) { var unwind = new AggregateUnwindOptions <ProductSubgroupView> { PreserveNullAndEmptyArrays = true }; return(mappings.Lookup("product_group", "product_group_code", "code", "ProductGroup") .Unwind("ProductGroup", unwind) .As <ProductSubgroupView>().Match(context.GetPostExpression())); }
// FIXME: check if we really can do it public override bool CanEvaluateToBool (IExpressionContext context) { return true; }
protected override IEnumerable <FieldInfo> GetMemberInfosForType(IExpressionContext context, Type type) { return(type.GetFields()); }
public ValueStackContext(IDbRefFactory dbRefFactory, IExpressionContext expressionContext) { _dbRefFactory = dbRefFactory; _expressionContext = expressionContext; }
public override string StringEvaluate(IExpressionContext context) { Token evaluatedToken = EvaluateToken(token, context); return(evaluatedToken.Value); }