コード例 #1
0
            protected override Expression VisitParameter(ParameterExpression variable)
            {
                if (VariableHasNotYetBeenAccessed(variable))
                {
                    _accessedVariables.Add(variable);
                }

                if (!JoinedAssignedVariables.Contains(variable))
                {
                    return(base.VisitParameter(variable));
                }

                var joinedAssignmentData = _constructsByAssignment
                                           .Where(kvp => kvp.Key.Left == variable)
                                           .Select(kvp => new
                {
                    Assignment = kvp.Key,
                    Construct  = kvp.Value
                })
                                           .FirstOrDefault();

                if ((joinedAssignmentData == null) || _constructs.Contains(joinedAssignmentData.Construct))
                {
                    return(base.VisitParameter(variable));
                }

                // This variable was assigned within a construct but is being accessed
                // outside of that scope, so the assignment shouldn't be joined:
                JoinedAssignedVariables.Remove(variable);
                JoinedAssignments.Remove(joinedAssignmentData.Assignment);
                _constructsByAssignment.Remove(joinedAssignmentData.Assignment);

                return(base.VisitParameter(variable));
            }
コード例 #2
0
            protected override Expression VisitBinary(BinaryExpression binary)
            {
                if ((binary.NodeType == ExpressionType.Assign) &&
                    (binary.Left.NodeType == ExpressionType.Parameter) &&
                    !JoinedAssignedVariables.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);
                        JoinedAssignedVariables.Add(variable);
                    }

                    AddAssignmentIfAppropriate(binary.Right);
                }

                return(base.VisitBinary(binary));
            }
コード例 #3
0
        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);
        }