From 2ebf654973bf4ea8cf60acf5627eb5566889b382 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Thu, 1 Nov 2018 16:36:56 -0500 Subject: [PATCH] added a ForEach extension for enumerables --- mRemoteV1/Tools/Extensions.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mRemoteV1/Tools/Extensions.cs b/mRemoteV1/Tools/Extensions.cs index 76bcba778..ad4eb66b2 100644 --- a/mRemoteV1/Tools/Extensions.cs +++ b/mRemoteV1/Tools/Extensions.cs @@ -1,9 +1,11 @@  using System; +using System.Collections.Generic; +using System.Linq; namespace mRemoteNG.Tools { - public static class Extensions + public static class Extensions { public static Optional Maybe(this T value) { @@ -50,5 +52,23 @@ namespace mRemoteNG.Tools throw new ArgumentException("Value cannot be null or empty", argName); return value; } + + /// + /// Perform an action for each item in the given collection. The item + /// is the pass along the processing chain. + /// + /// + /// + /// + /// + public static IEnumerable ForEach(this IEnumerable collection, Action action) + { + collection = collection.ToList(); + + foreach (var item in collection) + action(item); + + return collection; + } } }