 | enumerationHookEnumerationHookT Method (IEnumerableT, ActionT, ActionT, Action, Action) |
Namespace:
WhetStone.Looping
Assembly:
WhetStone (in WhetStone.dll) Version: 1.0.4.0 (1.0.0.0)
Syntaxpublic static IEnumerable<T> EnumerationHook<T>(
this IEnumerable<T> this,
Action<T> preYield = null,
Action<T> postYield = null,
Action begin = null,
Action end = null
)
Parameters
- this
- Type: System.Collections.GenericIEnumerableT
The IEnumerableT to hook to. - preYield (Optional)
- Type: SystemActionT
An ActionT to call before the element is returned to the enumeration caller. - postYield (Optional)
- Type: SystemActionT
An ActionT to call before the element is returned to the enumeration caller (if the next item is requested). - begin (Optional)
- Type: SystemAction
An Action to call before any element is enumerated. - end (Optional)
- Type: SystemAction
An Action to call after all elements are enumerated.
Type Parameters
- T
- The type of the IEnumerableT.
Return Value
Type:
IEnumerableTAn enumerable with the same elements, but whenever enumerated, will trigger a hooked method.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Examples
Say you want to find the sum and count of an
IEnumerableTval while only enumerating it once.
int count = 0;
int sum = val.EnumerationHook(a=>count++).Sum();
See Also