/// <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="parentProxy">Represents the parent item.</param> /// <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(CodeUnitProxy parentProxy, bool unsafeCode) { Param.AssertNotNull(parentProxy, "parentProxy"); Param.Ignore(unsafeCode); this.AdvanceToNextCodeSymbol(parentProxy); var queryClauseProxy = new CodeUnitProxy(this.document); Symbol symbol = this.PeekNextSymbol(); CsLanguageService.Debug.Assert(symbol.SymbolType == SymbolType.Other && symbol.Text == "orderby", "Expected an orderby keyword"); // Get and add the 'orderby' symbol. this.GetToken(queryClauseProxy, TokenType.OrderBy, SymbolType.Other); // Get each of the orderings in the clause. var orderings = new List<QueryOrderByOrdering>(); while (true) { var ordering = new QueryOrderByOrdering(); // Get the ordering expression. ordering.Expression = this.GetNextExpression(queryClauseProxy, ExpressionPrecedence.Query, unsafeCode); if (ordering.Expression == null) { throw this.CreateSyntaxException(); } // Get the order direction if it exists. symbol = this.PeekNextSymbol(); ordering.Direction = QueryOrderByDirection.Undefined; if (symbol.Text == "ascending") { ordering.Direction = QueryOrderByDirection.Ascending; this.GetToken(queryClauseProxy, TokenType.Ascending, SymbolType.Other); } else if (symbol.Text == "descending") { ordering.Direction = QueryOrderByDirection.Descending; this.GetToken(queryClauseProxy, TokenType.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.PeekNextSymbol(); if (symbol.SymbolType == SymbolType.Comma) { this.GetToken(queryClauseProxy, TokenType.Comma, SymbolType.Comma); } else { // This was the last ordering expression. break; } } // Create and return the clause. var orderByClause = new QueryOrderByClause(queryClauseProxy, orderings.AsReadOnly()); parentProxy.Children.Add(orderByClause); return orderByClause; }