public override bool Equals(Expression other)
        {
            LinqQueryExpression linqExpression = other as LinqQueryExpression;

            if (linqExpression == null || this.Clauses.Count != linqExpression.Clauses.Count)
            {
                return(false);
            }

            for (int i = 0; i < this.Clauses.Count; i++)
            {
                if (!this.Clauses[i].Equals(linqExpression.Clauses[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
            private bool TryMatchLinqQuery(MethodInvocationExpression methodInvocation, out LinqQueryExpression linqQuery)
            {
                Stack<MethodInvocationExpression> queryStack = new Stack<MethodInvocationExpression>();
                MethodInvocationExpression current = methodInvocation;
                bool isQueryableMethod = current.MethodExpression.MethodDefinition.IsQueryableMethod();
                while (current != null && current.MethodExpression.MethodDefinition.IsQueryMethod() && isQueryableMethod == current.MethodExpression.MethodDefinition.IsQueryableMethod())
                {
                    queryStack.Push(current);
                    current = current.Arguments[0] as MethodInvocationExpression;
                }

                if (queryStack.Count == 0)
                {
                    linqQuery = null;
                    return false;
                }

                MethodInvocationExpression top = queryStack.Peek();
                top.Arguments[0] = (Expression)Visit(top.Arguments[0]);
                linqQuery = ProcessExtensionMethodChain(queryStack, methodInvocation, isQueryableMethod);
                return linqQuery != null;
            }
 public override void VisitLinqQueryExpression(LinqQueryExpression node)
 {
     Indent();
     foreach (QueryClause clause in node.Clauses)
     {
         if (clause.CodeNodeType != CodeNodeType.IntoClause)
         {
             WriteLine();
         }
         else
         {
             WriteSpace();
         }
         Visit(clause);
     }
     Outdent();
 }
 public virtual void VisitLinqQueryExpression(LinqQueryExpression node)
 {
     foreach (QueryClause clause in node.Clauses)
     {
         Visit(clause);
     }
 }
 public override ICodeNode VisitLinqQueryExpression(LinqQueryExpression node)
 {
     return node;
 }
            private LinqQueryExpression RemoveTransparentIdentifiers(LinqQueryExpression originalQuery)
            {
                LinqQueryExpression linqQuery = (LinqQueryExpression)originalQuery.Clone();
                List<VariableReference> identifiers = new List<VariableReference>();
                TransparentIdentifierCleaner cleaner = new TransparentIdentifierCleaner();
                HashSet<VariableReference> transparentIdentifiers = new HashSet<VariableReference>();

                for (int i = 0; i < linqQuery.Clauses.Count; i++)
                {
                    linqQuery.Clauses[i] = (QueryClause)cleaner.Visit(linqQuery.Clauses[i]);
                    QueryClause currentClause = linqQuery.Clauses[i];

                    if (currentClause.CodeNodeType == CodeNodeType.FromClause)
                    {
                        identifiers.Add(GetVariableReference((currentClause as FromClause).Identifier));
                    }
                    else if (currentClause.CodeNodeType == CodeNodeType.JoinClause)
                    {
                        if (linqQuery.Clauses[i + 1].CodeNodeType != CodeNodeType.IntoClause)
                        {
                            identifiers.Add(GetVariableReference((currentClause as JoinClause).InnerIdentifier));
                        }
                        else
                        {
                            identifiers.Add(((IntoClause)linqQuery.Clauses[i + 1]).Identifier.Variable);
                            i++;
                        }
                    }
                    else if (currentClause.CodeNodeType == CodeNodeType.SelectClause && i != linqQuery.Clauses.Count - 1)
                    {
                        VariableReference intoIdentifier = ((IntoClause)linqQuery.Clauses[i + 1]).Identifier.Variable;
                        if (IsTransparentIdentifier(intoIdentifier))
                        {
                            Dictionary<PropertyDefinition, Expression> propertyToValueMap = GetPropertyToValueMap((currentClause as SelectClause).Expression);
                            if (propertyToValueMap == null)
                            {
                                return originalQuery;
                            }

                            if (identifiers.Count == 2)
                            {
                                if (!RemoveIdentifier(propertyToValueMap, identifiers))
                                {
                                    return originalQuery;
                                }
                                linqQuery.Clauses.RemoveAt(i);
                                linqQuery.Clauses.RemoveAt(i);
                                i--;
                            }
                            else if (identifiers.Count == 1)
                            {
                                LetClause letClause = GenerateLetClause(propertyToValueMap, identifiers[0]);
                                if (letClause == null)
                                {
                                    return originalQuery;
                                }
                                linqQuery.Clauses[i] = letClause;
                                linqQuery.Clauses.RemoveAt(i + 1);
                            }
                            else
                            {
                                return originalQuery;
                            }

                            this.methodContext.VariablesToRename.Add(intoIdentifier.Resolve());
                            transparentIdentifiers.Add(intoIdentifier);
                            identifiers.Clear();
                            identifiers.Add(intoIdentifier);
                            UpdateCleaner(cleaner, intoIdentifier, propertyToValueMap);
                        }
                    }
                    else if (currentClause.CodeNodeType == CodeNodeType.IntoClause)
                    {
                        identifiers.Clear();
                        identifiers.Add(((IntoClause)currentClause).Identifier.Variable);
                    }
                }

                TransparentIdentifierFinder finder = new TransparentIdentifierFinder(transparentIdentifiers);
                if (finder.ContainsTransparentIdentifiers(linqQuery))
                {
                    return originalQuery;
                }

                return linqQuery;
            }