Replace() public method

Creates a new SyntaxNodeOrTokenList with the specified element replaced with a new node or token.
public Replace ( Microsoft.CodeAnalysis.SyntaxNodeOrToken nodeOrTokenInList, Microsoft.CodeAnalysis.SyntaxNodeOrToken newNodeOrToken ) : SyntaxNodeOrTokenList
nodeOrTokenInList Microsoft.CodeAnalysis.SyntaxNodeOrToken The element to replace.
newNodeOrToken Microsoft.CodeAnalysis.SyntaxNodeOrToken The new node or token.
return SyntaxNodeOrTokenList
Esempio n. 1
0
        /// <summary>
        /// Creates a new list with the specified separator token replaced with the new separator.
        /// </summary>
        /// <param name="separatorToken">The separator token to be replaced.</param>
        /// <param name="newSeparator">The new separator token.</param>
        public SeparatedSyntaxList <TNode> ReplaceSeparator(SyntaxToken separatorToken, SyntaxToken newSeparator)
        {
            SyntaxNodeOrTokenList nodesWithSeps = this.GetWithSeparators();
            int index = nodesWithSeps.IndexOf(separatorToken);

            if (index < 0)
            {
                throw new ArgumentException("separatorToken");
            }

            if (newSeparator.RawKind != nodesWithSeps[index].RawKind ||
                newSeparator.Language != nodesWithSeps[index].Language)
            {
                throw new ArgumentException("newSeparator");
            }

            return(new SeparatedSyntaxList <TNode>(nodesWithSeps.Replace(separatorToken, newSeparator)));
        }