summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-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);
+ }
}
}