using System; using System.Collections.Generic; namespace PalGain.Core { /// /// A statically compiled "singleton" used to store objects throughout the /// lifetime of the app domain. Not so much singleton in the pattern's /// sense of the word as a standardized way to store single instances. /// /// The type of object to store. /// Access to the instance is not synchrnoized. public class Singleton : Singleton { static T instance; /// The singleton instance for the specified type T. Only one instance (at the time) of this object for each type of T. public static T Instance { get { return instance; } set { instance = value; AllSingletons[typeof(T)] = value; } } } /// /// Provides a singleton list for a certain type. /// /// The type of list to store. public class SingletonList : Singleton> { static SingletonList() { Singleton>.Instance = new List(); } /// The singleton instance for the specified type T. Only one instance (at the time) of this list for each type of T. public new static IList Instance { get { return Singleton>.Instance; } } } /// /// Provides a singleton dictionary for a certain key and vlaue type. /// /// The type of key. /// The type of value. public class SingletonDictionary : Singleton> { static SingletonDictionary() { Singleton>.Instance = new Dictionary(); } /// The singleton instance for the specified type T. Only one instance (at the time) of this dictionary for each type of T. public new static IDictionary Instance { get { return Singleton>.Instance; } } } /// /// Provides access to all "singletons" stored by . /// public class Singleton { static Singleton() { allSingletons = new Dictionary(); } static readonly IDictionary allSingletons; /// Dictionary of type to singleton instances. public static IDictionary AllSingletons { get { return allSingletons; } } } }