root / trunk / Pithos.Core / EnumerableExtensions.cs @ 70f12b36
History | View | Annotate | Download (814 Bytes)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics.Contracts; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
|
7 |
namespace Pithos.Core |
8 |
{ |
9 |
public static class EnumerableExtensions |
10 |
{ |
11 |
public static IEnumerable<T> Splice<T>(this IList<T> array,int startIndex,int endIndex=-1) |
12 |
{ |
13 |
if (array==null) |
14 |
throw new ArgumentNullException("array"); |
15 |
if (startIndex<0) |
16 |
throw new ArgumentOutOfRangeException("startIndex"); |
17 |
Contract.EndContractBlock(); |
18 |
|
19 |
if (startIndex>=array.Count) |
20 |
yield break; |
21 |
|
22 |
if (endIndex == -1) |
23 |
endIndex = array.Count; |
24 |
for (var i = startIndex; i < endIndex; i++) |
25 |
yield return array[i]; |
26 |
} |
27 |
|
28 |
|
29 |
} |
30 |
} |