diff --git a/CSharp/Plugins/UniversalEditor.Essential/Collections/Generic/AutoDictionary.cs b/CSharp/Plugins/UniversalEditor.Essential/Collections/Generic/AutoDictionary.cs index 7cc37f1b..5bef6898 100644 --- a/CSharp/Plugins/UniversalEditor.Essential/Collections/Generic/AutoDictionary.cs +++ b/CSharp/Plugins/UniversalEditor.Essential/Collections/Generic/AutoDictionary.cs @@ -6,31 +6,22 @@ using System.Text; namespace UniversalEditor.Collections.Generic { /// - /// Provides a that automatically adds or updates a key or value when it is - /// requested. + /// Provides a that automatically adds or updates a key or value when + /// it is requested. /// /// The type of the key part of the dictionary. /// The type of the value part of the dictionary. public class AutoDictionary : Dictionary { - public new TValue this[TKey key] - { - get { return this[key, default(TValue)]; } - set - { - if (ContainsKey(key)) - { - // we already contain an item with this key, so update the value accordingly - base[key] = value; - } - else - { - // we do not already contain an item with this key, so create a new value - base.Add(key, value); - } - } - } - public TValue this[TKey key, TValue defaultValue] + /// + /// Retrieves or updates an item with the specified key. If the item does not exist on update, + /// it will be created. If the item does not exist on retrieval, the value specified for + /// will be returned. + /// + /// The key of the item to retrieve or update. + /// The value returned on retrieval when the item with the specified key does not exist. + /// The item with the specified key if it exists in this collection; otherwise, defaultValue. + public TValue this[TKey key, TValue defaultValue = default(TValue)] { get { @@ -47,7 +38,12 @@ namespace UniversalEditor.Collections.Generic return defaultValue; } } - set { this[key] = value; } + set + { + // the .NET Framework Dictionary`2 implementation handles the "add or update" case + // automatically if a non-existent key is specified + this[key] = value; + } } } }