@@ -112,6 +112,53 @@ internal static int IndexOfTrailingWhitespace(IReadOnlyList<SyntaxTrivia> trivia
112112 return ( whiteSpaceStartIndex < triviaList . Count ) ? whiteSpaceStartIndex : - 1 ;
113113 }
114114
115+ /// <summary>
116+ /// Removes a range of elements from the <see cref="SyntaxTriviaList"/>.
117+ /// </summary>
118+ /// <param name="list">The list to remove elements from.</param>
119+ /// <param name="index">The zero-based starting index of the range of elements to remove.</param>
120+ /// <param name="count">The number of elements to remove.</param>
121+ /// <returns>A copy of <paramref name="list"/> with the specified range of elements removed.</returns>
122+ /// <exception cref="ArgumentOutOfRangeException">
123+ /// <para>If <paramref name="index"/> is less than 0.</para>
124+ /// <para>-or-</para>
125+ /// <para>If <paramref name="count"/> is less than 0.</para>
126+ /// </exception>
127+ /// <exception cref="ArgumentException">
128+ /// <para>If <paramref name="index"/> and <paramref name="count"/> do not denote a valid range of elements in
129+ /// the <see cref="SyntaxTriviaList"/>.</para>
130+ /// </exception>
131+ internal static SyntaxTriviaList RemoveRange ( this SyntaxTriviaList list , int index , int count )
132+ {
133+ if ( index < 0 )
134+ {
135+ throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
136+ }
137+
138+ if ( count < 0 )
139+ {
140+ throw new ArgumentOutOfRangeException ( nameof ( count ) ) ;
141+ }
142+
143+ if ( index > list . Count - count )
144+ {
145+ throw new ArgumentException ( "The specified range of elements does not exist in the list." ) ;
146+ }
147+
148+ SyntaxTrivia [ ] trivia = new SyntaxTrivia [ list . Count - count ] ;
149+ for ( int i = 0 ; i < index ; i ++ )
150+ {
151+ trivia [ i ] = list [ i ] ;
152+ }
153+
154+ for ( int i = index ; i + count < list . Count ; i ++ )
155+ {
156+ trivia [ i ] = list [ i + count ] ;
157+ }
158+
159+ return SyntaxFactory . TriviaList ( trivia ) ;
160+ }
161+
115162 /// <summary>
116163 /// Returns the index of the last trivia of a specified kind in the trivia list.
117164 /// </summary>
0 commit comments