Data/CafeLib.Data.Mapping/PropertyMap.cs
/// <summary>
/// Returns the <see cref="T:System.Reflection.MemberInfo"/> for the specified lambda expression.
/// </summary>
/// <param name="lambda">A lambda expression containing a MemberExpression.</param>
/// <returns>A MemberInfo object for the member in the specified lambda expression.</returns>
Returns the  for the specified lambda expression.
Returns the for the specified lambda expression .
private static MemberInfo GetMemberInfo(LambdaExpression lambda)
        {
            Expression expr = lambda;
            while (true)
            {
                switch (expr.NodeType)
                {
                    case ExpressionType.Lambda:
                        expr = ((LambdaExpression)expr).Body;
                        break;
                    case ExpressionType.Convert:
                        expr = ((UnaryExpression)expr).Operand;
                        break;
                    case ExpressionType.MemberAccess:
                        var memberExpression = (MemberExpression)expr;
                        var baseMember = memberExpression.Member;
                        while (memberExpression != null)
                        {
                            var type = memberExpression.Type;
                            if (type.GetMembers().Any(member => member.Name == baseMember.Name))
                            {
                                return type.GetMember(baseMember.Name).First();
                            }
                            memberExpression = memberExpression.Expression as MemberExpression;
                        }
                        var paramType = lambda.Parameters[0].Type;
                        return paramType.GetMember(baseMember.Name).First();
                    default:
                        return null;
                }
            }
        }
private static MemberInfo GetMemberInfo ( LambdaExpression lambda ) { Expression expr = lambda ; while ( true ) { switch ( expr . NodeType ) { case ExpressionType . Lambda : expr = ( ( LambdaExpression ) expr ) . Body ; break ; case ExpressionType . Convert : expr = ( ( UnaryExpression ) expr ) . Operand ; break ; case ExpressionType . MemberAccess : var memberExpression = ( MemberExpression ) expr ; var baseMember = memberExpression . Member ; while ( memberExpression != null ) { var type = memberExpression . Type ; if ( type . GetMembers ( ) . Any ( member => member . Name == baseMember . Name ) ) { return type . GetMember ( baseMember . Name ) . First ( ) ; } memberExpression = memberExpression . Expression as MemberExpression ; } var paramType = lambda . Parameters [ 0 ] . Type ; return paramType . GetMember ( baseMember . Name ) . First ( ) ; default : return null ; } } }
Returns the  for the specified lambda expression.
Returns the for the specified lambda expression .
// Make sure we get the property from the derived type.
A MemberInfo object for the member in the specified lambda expression.
A MemberInfo object for the member in the specified lambda expression .
lambda
LambdaExpression
A lambda expression containing a MemberExpression.
A lambda expression containing a MemberExpression .