using System; using System.Collections.Generic; using System.Linq; namespace StardewModdingAPI.Framework.Content { /// Encapsulates access and changes to dictionary content being read from a data file. internal class ContentEventHelperForDictionary : ContentEventData>, IContentEventHelperForDictionary { /********* ** Public methods *********/ /// Construct an instance. /// The content's locale code, if the content is localised. /// The normalised asset name being read. /// The content data being read. /// Normalises an asset key to match the cache key. public ContentEventHelperForDictionary(string locale, string assetName, IDictionary data, Func getNormalisedPath) : base(locale, assetName, data, getNormalisedPath) { } /// Add or replace an entry in the dictionary. /// The entry key. /// The entry value. public void Set(TKey key, TValue value) { this.Data[key] = value; } /// Add or replace an entry in the dictionary. /// The entry key. /// A callback which accepts the current value and returns the new value. public void Set(TKey key, Func value) { 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 Set(Func replacer) { foreach (var pair in this.Data.ToArray()) this.Data[pair.Key] = replacer(pair.Key, pair.Value); } } }