Mercurial > silverbladetech
annotate MetroWpf/MetroWpf.Framework/Extensions/EnumerableExtensions.cs @ 114:e51a6af1c98d
working version
author | adminsh@apollo |
---|---|
date | Sat, 19 May 2012 16:53:34 +0100 |
parents | 060f02cd4591 |
children |
rev | line source |
---|---|
15
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
1 using System; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
2 using System.Collections.Generic; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
3 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
4 namespace MetroWpf |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
5 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
6 /// <summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
7 /// Extension methods for all kinds of (typed) enumerable data (Array, List, ...) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
8 /// </summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
9 public static class EnumerableExtensions |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
10 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
11 #region · Extensions · |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
12 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
13 /// <summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
14 /// Converts all items of a list and returns them as enumerable. |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
15 /// </summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
16 /// <typeparam name="TSource">The source data type</typeparam> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
17 /// <typeparam name="TTarget">The target data type</typeparam> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
18 /// <param name="source">The source data.</param> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
19 /// <returns>The converted data</returns> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
20 /// <example> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
21 /// |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
22 /// var values = new[] { "1", "2", "3" }; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
23 /// values.ConvertList<string, int>().ForEach(Console.WriteLine); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
24 /// |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
25 /// </example> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
26 public static IEnumerable<TTarget> ConvertList<TSource, TTarget>(this IEnumerable<TSource> source) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
27 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
28 foreach (var value in source) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
29 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
30 yield return value.ConvertTo<TTarget>(); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
31 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
32 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
33 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
34 /// <summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
35 /// Performs an action for each item in the enumerable |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
36 /// </summary> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
37 /// <typeparam name="T">The enumerable data type</typeparam> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
38 /// <param name="values">The data values.</param> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
39 /// <param name="action">The action to be performed.</param> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
40 /// <example> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
41 /// |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
42 /// var values = new[] { "1", "2", "3" }; |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
43 /// values.ConvertList<string, int>().ForEach(Console.WriteLine); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
44 /// |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
45 /// </example> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
46 /// <remarks>This method was intended to return the passed values to provide method chaining. Howver due to defered execution the compiler would actually never run the entire code at all.</remarks> |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
47 public static void ForEach<T>(this IEnumerable<T> values, Action<T> action) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
48 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
49 foreach (var value in values) |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
50 { |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
51 action(value); |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
52 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
53 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
54 |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
55 #endregion |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
56 } |
060f02cd4591
Initial commit, pre airport work
stevenh7776 stevenhollidge@hotmail.com
parents:
diff
changeset
|
57 } |