summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/Content
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-08 15:30:27 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-08 15:30:27 -0500
commit28c78e8f25a0d062d0dda49bc089ebebef8bfa20 (patch)
treef7a10064799420daf692f8d6f24634735e079cb6 /src/StardewModdingAPI/Framework/Content
parentb2e88bccf63545d950f4cbf47a0466321c614245 (diff)
downloadSMAPI-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.cs9
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);
+ }
}
}