diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-08 15:30:27 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-08 15:30:27 -0500 |
commit | 28c78e8f25a0d062d0dda49bc089ebebef8bfa20 (patch) | |
tree | f7a10064799420daf692f8d6f24634735e079cb6 /src/StardewModdingAPI/Framework/Content | |
parent | b2e88bccf63545d950f4cbf47a0466321c614245 (diff) | |
download | SMAPI-28c78e8f25a0d062d0dda49bc089ebebef8bfa20.tar.gz SMAPI-28c78e8f25a0d062d0dda49bc089ebebef8bfa20.tar.bz2 SMAPI-28c78e8f25a0d062d0dda49bc089ebebef8bfa20.zip |
add dict content helper method to replace values based on a lambda (#173)
Diffstat (limited to 'src/StardewModdingAPI/Framework/Content')
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs | 9 |
1 files changed, 9 insertions, 0 deletions
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]); } + + /// <summary>Dynamically replace values in the dictionary.</summary> + /// <param name="replacer">A lambda which takes the current key and value for an entry, and returns the new value.</param> + public void Replace(Func<TKey, TValue, TValue> replacer) + { + foreach (var pair in this.Data.ToArray()) + this.Data[pair.Key] = replacer(pair.Key, pair.Value); + } } } |