CSharp examples for System.Reflection:PropertyInfo
Get LambdaExpression Property
using System.Text; using System.Linq.Expressions; using System.Linq; using System.Collections.Generic; using System.Reflection; using System;//from w w w. j a v a2 s . co m public class Main{ public static MemberInfo GetProperty(LambdaExpression lambda) { Expression expression = lambda; for (; ; ) { switch (expression.NodeType) { case ExpressionType.Lambda: expression = ((LambdaExpression)expression).Body; break; case ExpressionType.Convert: expression = ((UnaryExpression)expression).Operand; break; case ExpressionType.MemberAccess: MemberExpression memberExpression = (MemberExpression)expression; MemberInfo mi = memberExpression.Member; return mi; default: return null; } } } }