using DTT.Utils.Exceptions; using System; namespace DTT.Utils.Optimization { /// /// Provides an abstract implementation of a class that stores /// values and their constructor to create them the first time /// they are used. /// /// The type of key. /// The type of the value. public abstract class LazyDictionaryBase { /// /// The accessor to the collection. The argument should always be the name /// of the property. /// /// The name of the key. /// The collection value. public TValue this[TKey key] { get { try { return GetValue(key); } catch (Exception e) { throw new LazyDictionaryException($"Failed returning item for key {key}.", e); } } } /// /// Should return the item value based on the given key. /// /// The key to get the value for. /// The item value. protected abstract TValue GetValue(TKey key); } }