@@ -156,6 +156,78 @@ public readonly void Clear()
156
156
RefEnumerableHelper . Clear ( ref r0 , ( nint ) ( uint ) length , ( nint ) ( uint ) this . Step ) ;
157
157
}
158
158
159
+ /// <summary>
160
+ /// Copies the contents of this <see cref="RefEnumerable{T}"/> into a destination <see cref="RefEnumerable{T}"/> instance.
161
+ /// </summary>
162
+ /// <param name="destination">The destination <see cref="RefEnumerable{T}"/> instance.</param>
163
+ /// <exception cref="ArgumentException">
164
+ /// Thrown when <paramref name="destination"/> is shorter than the source <see cref="RefEnumerable{T}"/> instance.
165
+ /// </exception>
166
+ public readonly void CopyTo ( RefEnumerable < T > destination )
167
+ {
168
+ #if SPAN_RUNTIME_SUPPORT
169
+ if ( this . Step == 1 )
170
+ {
171
+ destination . CopyFrom ( this . Span ) ;
172
+
173
+ return ;
174
+ }
175
+
176
+ if ( destination . Step == 1 )
177
+ {
178
+ CopyTo ( destination . Span ) ;
179
+
180
+ return ;
181
+ }
182
+
183
+ ref T sourceRef = ref this . Span . DangerousGetReference ( ) ;
184
+ ref T destinationRef = ref destination . Span . DangerousGetReference ( ) ;
185
+ int
186
+ sourceLength = this . Span . Length ,
187
+ destinationLength = destination . Span . Length ;
188
+ #else
189
+ ref T sourceRef = ref RuntimeHelpers . GetObjectDataAtOffsetOrPointerReference < T > ( this . Instance , this . Offset ) ;
190
+ ref T destinationRef = ref RuntimeHelpers . GetObjectDataAtOffsetOrPointerReference < T > ( destination . Instance , destination . Offset ) ;
191
+ int
192
+ sourceLength = this . Length ,
193
+ destinationLength = destination . Length ;
194
+ #endif
195
+
196
+ if ( ( uint ) destinationLength < ( uint ) sourceLength )
197
+ {
198
+ ThrowArgumentExceptionForDestinationTooShort ( ) ;
199
+ }
200
+
201
+ RefEnumerableHelper . CopyTo ( ref sourceRef , ref destinationRef , ( nint ) ( uint ) sourceLength , ( nint ) ( uint ) this . Step , ( nint ) ( uint ) destination . Step ) ;
202
+ }
203
+
204
+ /// <summary>
205
+ /// Attempts to copy the current <see cref="RefEnumerable{T}"/> instance to a destination <see cref="RefEnumerable{T}"/>.
206
+ /// </summary>
207
+ /// <param name="destination">The target <see cref="RefEnumerable{T}"/> of the copy operation.</param>
208
+ /// <returns>Whether or not the operation was successful.</returns>
209
+ public readonly bool TryCopyTo ( RefEnumerable < T > destination )
210
+ {
211
+ #if SPAN_RUNTIME_SUPPORT
212
+ int
213
+ sourceLength = this . Span . Length ,
214
+ destinationLength = destination . Span . Length ;
215
+ #else
216
+ int
217
+ sourceLength = this . Length ,
218
+ destinationLength = destination . Length ;
219
+ #endif
220
+
221
+ if ( destinationLength >= sourceLength )
222
+ {
223
+ CopyTo ( destination ) ;
224
+
225
+ return true ;
226
+ }
227
+
228
+ return false ;
229
+ }
230
+
159
231
/// <summary>
160
232
/// Copies the contents of this <see cref="RefEnumerable{T}"/> into a destination <see cref="Span{T}"/> instance.
161
233
/// </summary>
0 commit comments