I need to read the values from one array, that is provided as an expression.
I have this method
public ExpressionAnalizer<TModel> where TModel : class
{
public string BuildExpression(Expression<Func<TModel, bool>> expression)
{
if (expression?.Body is MethodCallExpression)
return BuildMethodCallExpression(expression);
throw new ArgumentException($"The expression '{expression?.Body}' is unsupported");
}
public string BuildMethodCallExpression(Expression<Func<TModel, bool>> expression)
{
var body = expression.Body as MethodCallExpression;
//TODO: I can't find a property that has the values of IEnumerable
return null;
}
}
And is called like this
//PersonModel is a plain class with some properties.
var analizer= new ExpressionAnalizer<PersonModel>("");
var names = new List<string>() {"n1", "n2", "n3"};
//I want to get "Email contains ('n1', 'n2', 'n3')". I can read Email property, the call method name "Contains", but not itself values
var response = analizer.BuildExpression(x => names.Contains(x.Email));
Any idea? I was thinking to compile the expression, but I get stuck on "Closure" class, because System.Runtime.CompilerServices.Closure is private and I cannot use it.
By the way, I'm using .NET Core 1.0
EDIT
I need to get a string like
email contains ('n1','n2','n3')
And the input parameter need to be always an Expression
Expression<Func<TModel, bool>>
This is because internally, this method can receive any expression, like
x => x.SomeProperty == "n1"
Internally, I handle the expression.Body type and I have an implementation for different use cases.
The case I cannot figure how can I implement is when the input expression is
var someList = new List<string>() { "string1", "anotherString", "finalString" };
someObject.SomeProperty<SomeTModel>(x => someList.Contains(x.SomeProperty))