| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | |
| 4 | using Mono; |
| 5 | |
| 6 | #if !NET_3_5 && !NET_4_0 |
| 7 | |
| 8 | namespace System.Linq { |
| 9 | |
| 10 | static class Enumerable { |
| 11 | |
| 12 | public static IEnumerable<TRet> Select<TItem, TRet> (this IEnumerable<TItem> self, Func<TItem, TRet> selector) |
| 13 | { |
| 14 | foreach (var item in self) |
| 15 | yield return selector (item); |
| 16 | } |
| 17 | |
| 18 | public static IEnumerable<T> Where<T> (this IEnumerable<T> self, Func<T, bool> predicate) |
| 19 | { |
| 20 | foreach (var item in self) |
| 21 | if (predicate (item)) |
| 22 | yield return item; |
| 23 | } |
| 24 | |
| 25 | public static List<T> ToList<T> (this IEnumerable<T> self) |
| 26 | { |
| 27 | return new List<T> (self); |
| 28 | } |
| 29 | |
| 30 | public static T [] ToArray<T> (this IEnumerable<T> self) |
| 31 | { |
| 32 | return self.ToList ().ToArray (); |
| 33 | } |
| 34 | |
| 35 | public static T First<T> (this IEnumerable<T> self) |
| 36 | { |
| 37 | using (var enumerator = self.GetEnumerator ()) { |
| 38 | if (!enumerator.MoveNext ()) |
| 39 | throw new InvalidOperationException (); |
| 40 | |
| 41 | return enumerator.Current; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | #endif |