From 28c78e8f25a0d062d0dda49bc089ebebef8bfa20 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 8 Mar 2017 15:30:27 -0500 Subject: add dict content helper method to replace values based on a lambda (#173) --- .../Framework/Content/ContentEventHelperForDictionary.cs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/StardewModdingAPI/Framework') diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs index 8fcaae3c..9bfc16d8 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace StardewModdingAPI.Framework.Content { @@ -32,5 +33,13 @@ namespace StardewModdingAPI.Framework.Content { this.Data[key] = value(this.Data[key]); } + + /// Dynamically replace values in the dictionary. + /// A lambda which takes the current key and value for an entry, and returns the new value. + public void Replace(Func replacer) + { + foreach (var pair in this.Data.ToArray()) + this.Data[pair.Key] = replacer(pair.Key, pair.Value); + } } } -- cgit