internal static ImmutableList <Clause> ReadClauses(ref JReader r) { var builder = ImmutableList.CreateBuilder <Clause>(); for (var arr = r.ArrayOrNull(); arr.Next(ref r);) { UserAttribute attribute = new UserAttribute(); Operator op = null; ImmutableList <LdValue> values = null; bool negate = false; for (var obj = r.Object(); obj.Next(ref r);) { switch (obj.Name) { case var n when n == "attribute": attribute = UserAttribute.ForName(r.String()); break; case var n when n == "op": op = Operator.ForName(r.String()); // Operator.ForName never returns null - unrecognized operators return a stub object break; case var n when n == "values": values = ReadValues(ref r); break; case var n when n == "negate": negate = r.Bool(); break; } } builder.Add(new Clause(attribute, op, values, negate)); } return(builder.ToImmutable()); }
public ClauseBuilder Op(string opName) => Op(Operator.ForName(opName));
private static bool ApplyOperator(string opName, LdValue userValue, LdValue clauseValue) => ApplyOperator(Operator.ForName(opName), userValue, clauseValue);