Microsoft.CodeAnalysis.SyntaxNodeOrTokenList.ReplaceRange C# (CSharp) Method

ReplaceRange() public method

Creates a new SyntaxNodeOrTokenList with the specified element replaced with a new nodes and tokens.
public ReplaceRange ( Microsoft.CodeAnalysis.SyntaxNodeOrToken nodeOrTokenInList, IEnumerable newNodesAndTokens ) : SyntaxNodeOrTokenList
nodeOrTokenInList Microsoft.CodeAnalysis.SyntaxNodeOrToken The element to replace.
newNodesAndTokens IEnumerable The new nodes and tokens.
return SyntaxNodeOrTokenList
        public SyntaxNodeOrTokenList ReplaceRange(SyntaxNodeOrToken nodeOrTokenInList, IEnumerable<SyntaxNodeOrToken> newNodesAndTokens)
        {
            var index = this.IndexOf(nodeOrTokenInList);
            if (index >= 0 && index < this.Count)
            {
                var nodes = this.ToList();
                nodes.RemoveAt(index);
                nodes.InsertRange(index, newNodesAndTokens);
                return CreateList(nodeOrTokenInList.UnderlyingNode, nodes);
            }

            throw new ArgumentOutOfRangeException(nameof(nodeOrTokenInList));
        }