boolean expression with "contains" operator

Jan 14, 2008 at 8:44 PM
First of all, I like your program. It's very fast and easy to use. Maybe this is something I missed. Is there anyway you can do a boolean expression with "contains" operator? For example, if I pass in my datatype that contains a string[], can I do a "contains" check and returns a boolean value?
Coordinator
Jan 16, 2008 at 4:25 AM
Right now, there is no contains operator. I'm planning on putting one in in the next release. I'm still debating what the syntax will look like (either "var in (1, 2, 3)" or "in(a, 1, 2, 3)").

In the mean time, you can code a contains function and import it into the expression to get the same functionality:
public static class CustomFunctions
{
   public static bool Contains(string[] arr, string value)
   {
       return System.Array.IndexOf(arr, value) != -1;
   }
}

And then use it in an expression:
ExpressionContext context = new ExpressionContext();
context.Imports.ImportStaticMembers(typeof(CustomFunctions));
context.Variables.Add("arr", new string[] {"a", "b", "c"});
context.Variables.Add("value", "flee!");
 
IDynamicExpression e = ExpressionFactory.CreateDynamic("contains(arr, value)", context);
bool result = (bool)e.Evaluate();
Coordinator
Feb 6, 2008 at 3:34 AM
The In operator is implemented in Flee-0.9.16.0. You can find the documentation here