public void CustomOperator() { var data = new List <TestObject> { new TestObject { id = 1, name = "name1", active = false, state = TestObject.TestEnum.ValueA, value = 10.0f }, new TestObject { id = 2, name = "name2", active = true, state = TestObject.TestEnum.ValueB, value = 1000.0f }, }; const string op = "%"; m_QE.AddOperator(op); m_QE.AddOperatorHandler(op, (int ev, int fv) => ev % fv == 0); var query = m_QE.Parse("i%2"); ValidateNoErrors(query); var filteredValues = query.Apply(data).ToList(); Assert.IsNotEmpty(filteredValues); Assert.AreEqual(1, filteredValues.Count); Assert.Contains(data[1], filteredValues); query = m_QE.Parse("n%2"); Assert.IsFalse(query.valid); }
public static void SetupQueryEngine(QueryEngine qe) { qe.AddFilter("i", o => ((TestObject)o).id); qe.AddFilter("n", o => ((TestObject)o).name, new[] { ":", "=", "!=" }); qe.AddFilter("s", o => ((TestObject)o).state, new[] { "=", "!=", "<", ">", "<=", ">=" }); qe.AddFilter("a", o => ((TestObject)o).active, new[] { "=", "!=" }); qe.AddFilter("v", o => ((TestObject)o).value); qe.AddFilter <string>("is", IsFilterResolver); qe.AddFilter <int, int>("inc", ((o, context) => ((TestObject)o).id + context)); qe.AddOperatorHandler("=", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev == fv); qe.AddOperatorHandler("!=", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev != fv); qe.AddOperatorHandler("<", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev < fv); qe.AddOperatorHandler(">", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev > fv); qe.AddOperatorHandler("<=", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev <= fv); qe.AddOperatorHandler(">=", (TestObject.TestEnum ev, TestObject.TestEnum fv) => ev >= fv); qe.SetSearchDataCallback(o => { var to = o as TestObject; return(new[] { to.name, to.id.ToString() }); }); }