private void Visit(BinaryExpression binary) { if ((binary.NodeType == ExpressionType.Assign) && (binary.Left.NodeType == ExpressionType.Parameter) && !JoinedAssignmentVariables.Contains(binary.Left) && !_assignedAssignments.Contains(binary)) { var variable = (ParameterExpression)binary.Left; if (VariableHasNotYetBeenAccessed(variable)) { if (_constructs.Any()) { _constructsByAssignment.Add(binary, _constructs.Peek()); } JoinedAssignments.Add(binary); _accessedVariables.Add(variable); JoinedAssignmentVariables.Add(variable); } AddAssignmentIfAppropriate(binary.Right); } Visit(binary.Left); if (binary.Conversion != null) { Visit(binary.Conversion.Body); } Visit(binary.Right); }
private void Visit(ParameterExpression variable) { if (variable == null) { return; } if (VariableHasNotYetBeenAccessed(variable)) { _accessedVariables.Add(variable); } if (!JoinedAssignmentVariables.Contains(variable)) { return; } var joinedAssignmentData = _constructsByAssignment .Filter(kvp => kvp.Key.Left == variable) .Project(kvp => new { Assignment = kvp.Key, Construct = kvp.Value }) .FirstOrDefault(); if ((joinedAssignmentData == null) || _constructs.Contains(joinedAssignmentData.Construct)) { return; } // This variable was assigned within a construct but is being accessed // outside of that scope, so the assignment shouldn't be joined: JoinedAssignmentVariables.Remove(variable); JoinedAssignments.Remove(joinedAssignmentData.Assignment); _constructsByAssignment.Remove(joinedAssignmentData.Assignment); }