public static IEnumerable <SearchItem> If(SearchExpressionContext c) { if (c.args.Length < 2) { c.ThrowError("Not enough parameters for if"); } bool cond = false; foreach (var item in c.args[0].Execute(c)) { if (item == null) { yield return(null); } else { cond |= SearchExpression.IsTrue(item); if (!cond) { break; } } } if (cond) { foreach (var item in c.args[1].Execute(c)) { yield return(item); } } else if (c.args.Length == 2) { // Nothing to do. } else { foreach (var item in c.args[2].Execute(c)) { yield return(item); } } }
public static IEnumerable <SearchItem> IsTrue(SearchExpressionContext c) { foreach (var e in c.args) { bool isTrue = false; foreach (var item in e.Execute(c)) { if (item == null) { yield return(null); } else { isTrue |= SearchExpression.IsTrue(item); if (!isTrue) { break; } } } yield return(SearchExpression.CreateItem(isTrue, c.ResolveAlias(e, "IsTrue"))); } }
public static IEnumerable <SearchItem> ToBoolean(SearchExpressionContext c) { return(c.args.SelectMany(e => e.Execute(c)).Select(item => SearchExpression.CreateItem(SearchExpression.IsTrue(item)))); }