/
EnumerableAccess.cs
41 lines (38 loc) · 1.94 KB
/
EnumerableAccess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace NSupport {
using System.Collections.Generic;
using System.Linq;
/// <summary>
/// Provides extension methods for <see cref="IEnumerable{T}"/> for from/to conversion.
/// </summary>
public static class EnumerableAccess {
/// <summary>
/// Returns the tail of the element sequence from position.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">An <see cref="IEnumerable{T}"/> to return elements from.</param>
/// <param name="index">The index no to start from.</param>
/// <returns>Returns the tail of the element sequence from position.</returns>
public static IEnumerable<T> From<T>(this IEnumerable<T> source, int index) {
return source.Skip(index);
}
/// <summary>
/// Returns the beginning of the array up to position.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">An <see cref="IEnumerable{T}"/> to return elements from.</param>
/// <param name="index">The index no to stop at.</param>
/// <returns>Returns the beginning of the array up to position.</returns>
public static IEnumerable<T> To<T>(this IEnumerable<T> source, int index) {
return source.Take(++index);
}
/// <summary>
/// Determines whether a sequence is empty.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="source"/>.</typeparam>
/// <param name="source">An <see cref="IEnumerable{T}"/> to check for emptiness.</param>
/// <returns>true if the source sequence is null or contains no elements; otherwise, false.</returns>
public static bool IsEmpty<T>(this IEnumerable<T> source) {
return source == null || !source.Any();
}
}
}