///
/// Provides functionality of creating a singleton instance of a class.
///
/// The class to create as a singleton. This class must have a private constructor with no parameters.
//AJ: http://www.codeproject.com/cs/design/GenericSingletonPattern.asp
public static class ParameterlessSingleton
where T : class
{
///
/// Static constructor for lazy instaniation.
///
static ParameterlessSingleton()
{
}
///
/// The singleton instance of provided type T.
///
public static readonly T Instance =
typeof(T).InvokeMember(typeof(T).Name,
BindingFlags.CreateInstance |
BindingFlags.Instance |
BindingFlags.NonPublic,
null, null, null) as T;
}
This is an example property:
#region SingletonInstance
public static ExceptionLogger SingletonInstance
{
get
{
return Singleton.Instance;
}
}
#endregion