Answer the question
In order to leave comments, you need to log in
How to convert text from field to query logic?
Suppose that a very flexible filter is being created for a table, in which the logic is written by the operator.
The user opens a form in which, after some manipulations, he receives 5 (in our example) criteria:
Answer the question
In order to leave comments, you need to log in
You can use the simproexpr library .
Use something like this (beautify yourself, I just sketched a working example):
static void Main(string[] args)
{
var criteria = new Expression<Func<string, bool>>[]
{
str => str.Contains("дом"),
str => str.EndsWith("!"),
str => str.Substring(0, 1).ToUpper().Equals(str.Substring(0, 1)),
};
var complexCriterion = "1 | (2 & 3)";
var ep = new ExprParser();
LambdaExpression lambda = ep.Parse("(string str) => " + BuildComplexCriterion(complexCriterion, criteria));
var result = ep.Run(lambda, "дом");
}
static string BuildComplexCriterion(string complexCriterion, Expression<Func<string, bool>>[] criteria)
{
for (var i = 0; i < criteria.Length; ++i)
{
complexCriterion = complexCriterion.Replace((i + 1).ToString(), criteria[i].Body.ToString());
}
return complexCriterion;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question