/// <summary>
        /// Initializes a new instance of the FilterBuildingExpressionVisitor
        /// class.
        /// </summary>
        /// <param name="contractResolver">
        /// The contract resolver to use to determine property
        /// names from members used within expressions.
        /// </param>
        private FilterBuildingExpressionVisitor(MobileServiceContractResolver contractResolver)
            : base()
        {
            Debug.Assert(contractResolver != null);

            this.contractResolver = contractResolver;
        }
        /// <summary>
        /// Translate an expression tree into a compiled OData query.
        /// </summary>
        /// <param name="expression">
        /// The expression tree.
        /// </param>
        /// <param name="contractResolver">
        /// The contract resolver used to determine property names from
        /// members used within expressions.
        /// </param>
        /// <returns>
        /// An OData query.
        /// </returns>
        public static string Create(Expression expression, MobileServiceContractResolver contractResolver)
        {
            Debug.Assert(expression != null);
            Debug.Assert(contractResolver != null);

            // Walk the expression tree and build the filter.
            FilterBuildingExpressionVisitor visitor = new FilterBuildingExpressionVisitor(contractResolver);

            visitor.Visit(expression);
            return(visitor.filter.ToString());
        }
        /// <summary>
        /// Get the table member name referenced by an expression or return null.
        /// </summary>
        /// <param name="expression">
        /// The expression to check.
        /// </param>
        /// <param name="contractResolver">
        /// The contract resolver to use to determine property names from members used
        /// within expressions.
        /// </param>
        /// <returns>
        /// The table member name or null.
        /// </returns>
        public static string GetTableMemberName(Expression expression,
                                                MobileServiceContractResolver contractResolver)
        {
            Debug.Assert(expression != null);
            Debug.Assert(contractResolver != null);

            // Only parameter references are valid in a query (any other
            // references should have been partially evaluated away)
            MemberExpression member = expression as MemberExpression;

            if (member != null &&
                member.Expression != null &&
                member.Expression.NodeType == ExpressionType.Parameter &&
                member.Member != null)
            {
                // Lookup the Mobile Services name of the member and use that
                JsonProperty property = contractResolver.ResolveProperty(member.Member);
                return(property.PropertyName);
            }

            // Otherwise return null
            return(null);
        }
        /// <summary>
        /// Get the table member name referenced by an expression or return null.
        /// </summary>
        /// <param name="expression">
        /// The expression to check.
        /// </param>
        /// <param name="contractResolver">
        /// The contract resolver to use to determine property names from members used 
        /// within expressions.
        /// </param>
        /// <returns>
        /// The table member name or null.
        /// </returns>
        public static string GetTableMemberName(Expression expression,
                                                  MobileServiceContractResolver contractResolver)
        {
            Debug.Assert(expression != null);
            Debug.Assert(contractResolver != null);

            // Only parameter references are valid in a query (any other
            // references should have been partially evaluated away)
            MemberExpression member = expression as MemberExpression;
            if (member != null &&
                member.Expression != null &&
                member.Expression.NodeType == ExpressionType.Parameter &&
                member.Member != null)
            {
                // Lookup the Mobile Services name of the member and use that
                JsonProperty property = contractResolver.ResolveProperty(member.Member);
                return property.PropertyName;
            }

            // Otherwise return null
            return null;
        }
 /// <summary>
 /// Translate an expression tree into a compiled OData query.
 /// </summary>
 /// <param name="expression">
 /// The expression tree.
 /// </param>
 /// <param name="contractResolver">
 /// The contract resolver used to determine property names from
 /// members used within expressions.
 /// </param>
 /// <returns>
 /// An OData query.
 /// </returns>
 public static string Create(Expression expression, MobileServiceContractResolver contractResolver)
 {
     Debug.Assert(expression != null);
     Debug.Assert(contractResolver != null);
             
     // Walk the expression tree and build the filter.
     FilterBuildingExpressionVisitor visitor = new FilterBuildingExpressionVisitor(contractResolver);
     visitor.Visit(expression);
     return visitor.filter.ToString();
 }
        /// <summary>
        /// Initializes a new instance of the FilterBuildingExpressionVisitor
        /// class.
        /// </summary>
        /// <param name="contractResolver">
        /// The contract resolver to use to determine property 
        /// names from members used within expressions.
        /// </param>
        private FilterBuildingExpressionVisitor(MobileServiceContractResolver contractResolver)
            : base()
        {
            Debug.Assert(contractResolver != null);

            this.contractResolver = contractResolver;
        }