You can get the PropertyInfo object by looking at the passed expression. Something like:
public void Add<T>(Expression<Func<T,object>> expression, string displayName) { var memberExpression = expression.Body as MemberExpression; PropertyInfo prop = memberExpression.Member as PropertyInfo;
This is an incomplete implementation, because I donβt know what exactly you want to do with this property, but it shows how to get PropertyInfo from an expression - the PropertyInfo object contains all the metadata about this property. Also, be sure to add the error handling above before applying it in production code (i.e. Protect from an expression other than MemberExpression, etc.).
driis Aug 24 '10 at 17:09 2010-08-24 17:09
source share