Posted By

jmcd on 02/12/10


Tagged

Expression Linq


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


Dynamicaly Creating Expression Accessing a Property


 / Published in: C#
 

Creating the equivalent of (ParentType x) => x.SomeProperty when the property is unknown until runtime

  1. var parameterExpression = Expression.Parameter(typeof(ParentType), "x");
  2. var memberExpression = Expression.Property(parameterExpression, propertyName);
  3. var result = (Expression<Func<ParentType, PropertyType>>)Expression.Lambda(memberExpression, parameterExpression);

Report this snippet  

You need to login to post a comment.