Example #1
0
        internal static bool IsMemberEqualsValueExpression(Expression exp, Type declaringType, string memberName)
        {
            if (exp.NodeType != ExpressionType.Equal)
            {
                return(false);
            }

            BinaryExpression be = (BinaryExpression)exp;

            // Assert.
            if (ExpressionTreeHelpers.IsSpecificMemberExpression(be.Left, declaringType, memberName) &&
                ExpressionTreeHelpers.IsSpecificMemberExpression(be.Right, declaringType, memberName))
            {
                throw new Exception("Cannot have 'member' == 'member' in an expression!");
            }

            return(ExpressionTreeHelpers.IsSpecificMemberExpression(be.Left, declaringType, memberName) ||
                   ExpressionTreeHelpers.IsSpecificMemberExpression(be.Right, declaringType, memberName));
        }
Example #2
0
 protected override Expression VisitBinary(BinaryExpression be)
 {
     if (be.NodeType == ExpressionType.Equal)
     {
         if (ExpressionTreeHelpers.IsMemberEqualsValueExpression(be, typeof(Place), "Name"))
         {
             locations.Add(ExpressionTreeHelpers.GetValueFromEqualsExpression(be, typeof(Place), "Name"));
             return(be);
         }
         else if (ExpressionTreeHelpers.IsMemberEqualsValueExpression(be, typeof(Place), "State"))
         {
             locations.Add(ExpressionTreeHelpers.GetValueFromEqualsExpression(be, typeof(Place), "State"));
             return(be);
         }
         else
         {
             return(base.VisitBinary(be));
         }
     }
     else
     {
         return(base.VisitBinary(be));
     }
 }