@@ -59,6 +59,20 @@ public ref struct ReadOnlyRefEnumerable<T>
59
59
private int position ;
60
60
61
61
#if SPAN_RUNTIME_SUPPORT
62
+ /// <summary>
63
+ /// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
64
+ /// </summary>
65
+ /// <param name="span">The <see cref="ReadOnlySpan{T}"/> instance pointing to the first item in the target memory area.</param>
66
+ /// <param name="step">The distance between items in the sequence to enumerate.</param>
67
+ /// <param name="position">The current position in the sequence.</param>
68
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
69
+ private ReadOnlyRefEnumerable ( ReadOnlySpan < T > span , int step , int position )
70
+ {
71
+ this . span = span ;
72
+ this . step = step ;
73
+ this . position = position ;
74
+ }
75
+
62
76
/// <summary>
63
77
/// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
64
78
/// </summary>
@@ -73,6 +87,24 @@ internal ReadOnlyRefEnumerable(in T reference, int length, int step)
73
87
this . position = - 1 ;
74
88
}
75
89
#else
90
+ /// <summary>
91
+ /// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
92
+ /// </summary>
93
+ /// <param name="instance">The target <see cref="object"/> instance.</param>
94
+ /// <param name="offset">The initial offset within <see paramref="instance"/>.</param>
95
+ /// <param name="length">The number of items in the sequence.</param>
96
+ /// <param name="step">The distance between items in the sequence to enumerate.</param>
97
+ /// <param name="position">The current position in the sequence.</param>
98
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
99
+ private ReadOnlyRefEnumerable ( object ? instance , IntPtr offset , int length , int step , int position )
100
+ {
101
+ this . instance = instance ;
102
+ this . offset = offset ;
103
+ this . length = length ;
104
+ this . step = step ;
105
+ this . position = position ;
106
+ }
107
+
76
108
/// <summary>
77
109
/// Initializes a new instance of the <see cref="ReadOnlyRefEnumerable{T}"/> struct.
78
110
/// </summary>
@@ -204,6 +236,20 @@ public readonly T[] ToArray()
204
236
return array ;
205
237
}
206
238
239
+ /// <summary>
240
+ /// Implicitly converts a <see cref="RefEnumerable{T}"/> instance into a <see cref="ReadOnlyRefEnumerable{T}"/> one.
241
+ /// </summary>
242
+ /// <param name="enumerable">The input <see cref="RefEnumerable{T}"/> instance.</param>
243
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
244
+ public static implicit operator ReadOnlyRefEnumerable < T > ( RefEnumerable < T > enumerable )
245
+ {
246
+ #if SPAN_RUNTIME_SUPPORT
247
+ return new ReadOnlyRefEnumerable < T > ( enumerable . Span , enumerable . Step , enumerable . Position ) ;
248
+ #else
249
+ return new ReadOnlyRefEnumerable < T > ( enumerable . Instance , enumerable . Offset , enumerable . Length , enumerable . Position ) ;
250
+ #endif
251
+ }
252
+
207
253
/// <summary>
208
254
/// Throws an <see cref="ArgumentException"/> when the target span is too short.
209
255
/// </summary>
0 commit comments