jeudi 18 février 2016

create Lambda Expression with reflection in c#

I need to Create the following Lambda Expression :

{d=>d.Name.NameEn}

I wrote the following code:

ParameterExpression parameter = Expression.Parameter(typeof(T), "d");
MemberExpression memberExpression = Expression.Property(parameter, typeof(T).GetProperty("Name"));
LambdaExpression lambda = Expression.Lambda(memberExpression, parameter);

Output :

{d => d.Name}

But I need this :

{d=>d.Name.NameEn}

How to make this ?

update:

my class :

 public class T
    {
        public U Name { get; set; }
    }
    public class U
    {
        public string NameEn { get; set; }
    }





Aucun commentaire:

Enregistrer un commentaire