Get the parameter value from a Linq Expression

前端 未结 3 594
别跟我提以往
别跟我提以往 2021-01-01 16:21

I have the following class

public class MyClass
{
    public bool Delete(Product product)
    {
        // some code.
    }
}

Now I have a

3条回答
  •  萌比男神i
    2021-01-01 16:43

    You can compile the argument expression and then invoke it to calculate the value:

    var values = new List();
    foreach(var arg in body.Arguments)
    {
        var value = Expression.Lambda(argument).Compile().DynamicInvoke();
        values.Add(value);
    }
    this.ArgValues = values.ToArray();
    
        

    提交回复
    热议问题