Skip to content

Commit 9e2ae0d

Browse files
committed
把之前删掉的自带的 Slice 加回来
1 parent edb69b8 commit 9e2ae0d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/DotNetCampus.CommandLine/Utils/Collections/ReadOnlyListRange.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public ReadOnlyListRange(IReadOnlyList<T> sourceList, Range range)
2828
? throw new ArgumentOutOfRangeException(nameof(index))
2929
: _sourceList[_range.GetOffsetAndLength(_sourceList.Count).Offset + index];
3030

31+
public ReadOnlyListRange<T> Slice(int offset, int length)
32+
{
33+
if (_sourceList is null)
34+
{
35+
return offset is 0 && length is 0
36+
? new ReadOnlyListRange<T>([], new Range(0, 0))
37+
: throw new ArgumentOutOfRangeException(nameof(length));
38+
}
39+
40+
var (start, _) = _range.GetOffsetAndLength(_sourceList.Count);
41+
return new ReadOnlyListRange<T>(_sourceList, new Range(start + offset, start + offset + length));
42+
}
43+
3144
public IEnumerator<T> GetEnumerator()
3245
{
3346
if (_sourceList is null)

0 commit comments

Comments
 (0)