开发者

Expression Trees Conversion

开发者 https://www.devze.com 2023-01-11 19:42 出处:网络
I have two Classes : class Customer { public string Fullname { get; set; } public string Lastname { get; set; }

I have two Classes :

class Customer
{
    public string Fullname { get; set; }
    public string Lastname { get; set; }
    public int Age { get; set; }
}

and

class CustomerDTO
{
    public string Fullname { get; set; }
    public string Lastname { get; set; }
    public int Age { get; set; }
}

now i h开发者_如何转开发ave an expressiontree Expression<Func<Customer, bool>> expression Passed between layers , can i convert it to Expression<Func<CustomerDTO, bool>> expression to be able to use it since it would give compile time error!

thanks in advance


nevermind i made it

Expression<Func<Customer, bool>> expression = v => v.Fullname == "Johm";
         var par = Expression.Parameter(typeof(CustomerDTO));
         Expression<Func<CustomerDTO, bool>> ex = (Expression<Func<CustomerDTO, bool>>)Expression.Lambda(expression.Body, par);
0

精彩评论

暂无评论...
验证码 换一张
取 消