My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#region Copyright
// *******************************************************************************
// Copyright (c) 2000-2009 Paul Stancer.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// Paul Stancer - initial implementation
// *******************************************************************************
#endregion
#region using
using System;
using System.Text;
using System.IO;
using System.Security;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;

using System.Threading;

using Ximura;
#endregion // using
namespace Ximura
{
public static partial class LinqHelper
{
#region ForEach<T>(this IEnumerable<T> items, Action<T> action)
/// <summary>
/// The ForEach extension iterates through the items collection, and executes the action for each item.
/// </summary>
/// <example>
/// A quick use of the method would be as follows:
///
/// Enumerable.Range(0,40).ForEach(i => Console.WriteLine(i));
///
/// which is equivalent to the following code:
///
/// foreach(var i in Enumerable.Range(0,40))
/// Console.WriteLine(i);
/// </example>
/// <typeparam name="T">The item type to process.</typeparam>
/// <param name="items">The collection of items to process.</param>
/// <param name="action">The action to be executed against each item in the collection.</param>
public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
{
if (items == null) throw new ArgumentNullException("items", "The items enumeration cannot be null.");
if (action == null) throw new ArgumentNullException("action", "The action delegate cannot be null.");

foreach (var item in items)
action(item);
}
#endregion

#region ForIndex<T>(this IEnumerable<T> items, Action<int, T> action)
/// <summary>
/// The ForIndex extension method iterates through the items collection, and executes the action for each item and provides
/// a 32-bit integer index parameter that identifies the position of the item in the collection.
/// </summary>
/// <typeparam name="T">The item type to process.</typeparam>
/// <param name="items">The collection of items to process.</param>
/// <param name="action">The action to be executed against each item in the collection.</param>
public static void ForIndex<T>(this IEnumerable<T> items, Action<int, T> action)
{
if (items == null) throw new ArgumentNullException("items", "items enumeration is null");
if (action == null) throw new ArgumentNullException("action", "the action delegate is null");

int index = 0;
foreach (var item in items)
{
action(index, item);
index++;
}
}
#endregion // ForIndex<T>(this IEnumerable<T> items, Action<int, T> action)
#region ForBigIndex<T>(this IEnumerable<T> items, Action<long, T> action)
/// <summary>
/// The ForBigIndex extension method iterates through the items collection, and executes the action for each item and provides
/// a 64-bit integer parameter that identifies the position of the item in the collection.
/// </summary>
/// <typeparam name="T">The item type to process.</typeparam>
/// <param name="items">The collection of items to process.</param>
/// <param name="action">The action to be executed against each item in the collection.</param>
public static void ForBigIndex<T>(this IEnumerable<T> items, Action<long, T> action)
{
if (items == null) throw new ArgumentNullException("items", "items enumeration is null");
if (action == null) throw new ArgumentNullException("action", "the action delegate is null");

long index = 0;
foreach (var item in items)
{
action(index, item);
index++;
}
}
#endregion // ForIndex<T>(this IEnumerable<T> items, Action<long, T> action)

#region ForReverseIndex<T>(this IList<T> items, Action<int, T> action)
/// <summary>
/// The ForIndex extension method iterates through a list in reverse, and executes the action for each item and provides
/// a 32-bit integer index parameter that identifies the position of the item in the list.
/// </summary>
/// <typeparam name="T">The item type to process.</typeparam>
/// <param name="items">The list of items to process.</param>
/// <param name="action">The action to be executed against each item in the collection.</param>
public static void ForReverseIndex<T>(this IList<T> items, Action<int, T> action)
{
if (items == null) throw new ArgumentNullException("items", "items enumeration is null");
if (action == null) throw new ArgumentNullException("action", "the action delegate is null");

int length = items.Count;
for (int index = length - 1; index >= 0;index-- )
{
action(index, items[index]);
}
}
#endregion // ForReverseIndex<T>(this IList<T> items, Action<int, T> action)
}
}

Change log

r228 by pstancer on Jul 17, 2011   Diff
Update to settings and clean up of code.
Go to: 
Project members, sign in to write a code review

Older revisions

r174 by pstancer on Mar 30, 2010   Diff
Expanded CommandContainer, with
changes to persistence layer.
r164 by pstancer on Mar 24, 2010   Diff
Fixed a few additional namespace
issues to rationalise the project
structure.
r162 by kord.manny on Mar 24, 2010   Diff
Rationalised namespaces for Ximura
All revisions of this file

File info

Size: 5924 bytes, 126 lines
Powered by Google Project Hosting