Exemplo n.º 1
0
        public override SyntaxNode VisitParameterList(ParameterListSyntax node)
        {
            ParameterListSyntax originalNode = node;
            //node = (ParameterListSyntax)base.VisitParameterList(node); can't - see below

            int i = 0;

            foreach (ParameterSyntax parameter in originalNode.Parameters)
            {
                if (RemoveParameter(parameter))
                {
                    node = node.Update(
                        node.OpenParenToken,
                        node.Parameters.RemoveAt(i),
                        node.CloseParenToken);
                    continue;
                }
                // Can't use base.VisitParameterList(node) to inner-process all parameters because some that are destined
                // to be stripped may cause processing errors (e.g. because they contain a generic type reference to a type
                // parameter that is being eliminated). Therefore, do the work ourselves using base.VisitParameter(parameter)
                // on each.
                bool        hasTrailingSeparator = i < node.Parameters.Count - 1;
                bool        hasLeadingSeparator  = i > 0;
                SyntaxToken originalSeparator    = hasTrailingSeparator
                    ? node.Parameters.GetSeparator(i)
                    : (hasLeadingSeparator
                        ? node.Parameters.GetSeparator(i - 1)
                        : SyntaxFactory.MissingToken(SyntaxKind.CommaToken));
                SeparatedSyntaxList <ParameterSyntax> parameters = node.Parameters
                                                                   .RemoveAt(i)
                                                                   .Insert(i, (ParameterSyntax)base.VisitParameter(parameter).WithTriviaFrom(node.Parameters[i]));
                if (hasTrailingSeparator)
                {
                    parameters = parameters.ReplaceSeparator(parameters.GetSeparator(i), originalSeparator);
                }
                else if (hasLeadingSeparator)
                {
                    parameters = parameters.ReplaceSeparator(parameters.GetSeparator(i - 1), originalSeparator);
                }
                node = node.Update(
                    node.OpenParenToken,
                    parameters,
                    node.CloseParenToken);
                i++;
            }

            return(node);
        }