/Test/Mono.Cecil.Tests/Linq.cs
C# | 47 lines | 36 code | 11 blank | 0 comment | 3 complexity | 81d2c5ace0808103a747a8da34981915 MD5 | raw file
1using System; 2using System.Collections.Generic; 3 4using Mono; 5 6#if !NET_3_5 && !NET_4_0 7 8namespace 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