mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-14 05:36:07 +00:00
27 lines
728 B
C#
27 lines
728 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BinaryObjectScanner
|
|
{
|
|
internal static class EnumerableExtensions
|
|
{
|
|
/// <summary>
|
|
/// Wrap iterating through an enumerable with an action
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// .NET Frameworks 2.0 and 3.5 process in series.
|
|
/// .NET Frameworks 4.0 onward process in parallel.
|
|
/// </remarks>
|
|
public static void IterateWithAction<T>(this IEnumerable<T> source, Action<T> action)
|
|
{
|
|
#if NET20 || NET35
|
|
foreach (var item in source)
|
|
{
|
|
action(item);
|
|
}
|
|
#else
|
|
System.Threading.Tasks.Parallel.ForEach(source, action);
|
|
#endif
|
|
}
|
|
}
|
|
} |