Posted By

jmcd on 02/12/10


Expression Linq

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


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.