Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 |
|
---|
4 | namespace Microsoft.Research.DynamicDataDisplay
|
---|
5 | {
|
---|
6 | internal static class ListExtensions
|
---|
7 | {
|
---|
8 | /// <summary>
|
---|
9 | /// Gets last element of list.
|
---|
10 | /// </summary>
|
---|
11 | /// <typeparam name="T"></typeparam>
|
---|
12 | /// <param name="list"></param>
|
---|
13 | /// <returns></returns>
|
---|
14 | internal static T GetLast<T>(this List<T> list)
|
---|
15 | {
|
---|
16 | if (list == null) throw new ArgumentNullException("list");
|
---|
17 | if (list.Count == 0) throw new InvalidOperationException(Strings.Exceptions.CannotGetLastElement);
|
---|
18 |
|
---|
19 | return list[list.Count - 1];
|
---|
20 | }
|
---|
21 |
|
---|
22 | internal static void ForEach<T>(this IEnumerable<T> source, Action<T> action) {
|
---|
23 | if (action == null)
|
---|
24 | throw new ArgumentNullException("action");
|
---|
25 | if (source == null)
|
---|
26 | throw new ArgumentNullException("source");
|
---|
27 |
|
---|
28 | foreach (var item in source)
|
---|
29 | {
|
---|
30 | action(item);
|
---|
31 | }
|
---|
32 | }
|
---|
33 | }
|
---|
34 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.