Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether this value is equal to the given object.
        /// </summary>
        /// <param name="obj">
        /// The object to compare against.
        /// </param>
        /// <returns>
        /// Returns true if the objects are equal.
        /// </returns>
        public override bool Equals(object obj)
        {
            Param.Ignore(obj);

            if (obj == null)
            {
                return(false);
            }

            QueryOrderByOrdering item = (QueryOrderByOrdering)obj;

            return(item.Expression == this.expression && item.Direction == this.direction);
        }
        /// <summary>
        /// Gets a query order-by clause.
        /// </summary>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides 
        /// in an unsafe code block.</param>
        /// <returns>Returns the query order-by clause.</returns>
        private QueryOrderByClause GetQueryOrderByClause(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            // Get and add the 'orderby' symbol.
            Symbol symbol = this.GetNextSymbol(SymbolType.Other);
            Debug.Assert(symbol.Text == "orderby", "Expected an orderby keyword");

            Node<CsToken> firstTokenNode = this.tokens.InsertLast(this.GetToken(CsTokenType.OrderBy, SymbolType.Other));

            // Get each of the orderings in the clause.
            List<QueryOrderByOrdering> orderings = new List<QueryOrderByOrdering>();

            while (true)
            {
                QueryOrderByOrdering ordering = new QueryOrderByOrdering();

                // Get the ordering expression.
                ordering.Expression = this.GetNextExpression(ExpressionPrecedence.Query, unsafeCode);
                if (ordering.Expression == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Get the order direction if it exists.
                symbol = this.GetNextSymbol();

                ordering.Direction = QueryOrderByDirection.Undefined;

                if (symbol.Text == "ascending")
                {
                    ordering.Direction = QueryOrderByDirection.Ascending;
                    this.tokens.Add(this.GetToken(CsTokenType.Ascending, SymbolType.Other));
                }
                else if (symbol.Text == "descending")
                {
                    ordering.Direction = QueryOrderByDirection.Descending;
                    this.tokens.Add(this.GetToken(CsTokenType.Descending, SymbolType.Other));
                }

                // Add the ordering to the list.
                orderings.Add(ordering);

                // If the next symbol is a comma, then we should continue and get the next ordering expression.
                symbol = this.GetNextSymbol();

                if (symbol.SymbolType == SymbolType.Comma)
                {
                    this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma));
                }
                else
                {
                    // This was the last ordering expression.
                    break;
                }
            }

            // Create and return the clause.
            return new QueryOrderByClause(
                new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last),
                orderings);
        }