This question is locked. New answers and comments are not allowed.
I want to be able to filter information out of a list of dictionaries.
Code as follows
It gives me all trues :(
I'm clearly missing something here.
Ideally, I would like to latch onto "CreateFilterExpression" else I would just create one from scratch which would be rather pointless if you guys have a better solution.
Code as follows
List<
Dictionary
<string, int>> data = new List<
Dictionary
<string, int>>();
data.Add(new Dictionary<
string
, int>() { { "col1", 99 }, { "col2", 99 } });
data.Add(new Dictionary<
string
, int>() { { "col1", 101 }, { "col2", 101 } });
data.Add(new Dictionary<
string
, int>() { { "col1", 99 }, { "col2", 201 } });
FilterDescriptor filterDescriptor = new FilterDescriptor("col1", FilterOperator.IsLessThanOrEqualTo, 100);
filterDescriptor.MemberType = typeof(int);
ParameterExpression values = Expression.Parameter(typeof(Dictionary<
string
, int>));
Expression expression = filterDescriptor.CreateFilterExpression(values);
var compiledExpression = Expression.Lambda<
Func
<Dictionary<string, int>, bool>>(expression, values).Compile();
foreach(var item in data)
{
System.Diagnostics.Debug.WriteLine(item["col1"]);
if (compiledExpression.Invoke(item))
{
System.Diagnostics.Debug.WriteLine("true");
}
else
{
System.Diagnostics.Debug.WriteLine("false");
}
}
It gives me all trues :(
I'm clearly missing something here.
Ideally, I would like to latch onto "CreateFilterExpression" else I would just create one from scratch which would be rather pointless if you guys have a better solution.