View Code public static class SingletonProvider <T> where T: new ()
{
Private static T m_instance;
Private static readonly object sync = new object ();
/// <Summary>
/// The generic single column of the constructor is insufficient.
/// </Summary>
Public static T Instance
{
Get
{
If (m_instance = null)
{
Lock (sync)
{
If (m_instance = null)
{
Try
{
M_instance = new T ();
}
Catch
{
}
}
}
}
Return m_instance;
}
}
/// <Summary>
/// Generic Single-Column mode with Constructor
/// </Summary>
Public static T InstanceForParameter (params object [] objarr)
{
If (m_instance = null)
{
Lock (sync)
{
If (m_instance = null)
{
Var t = typeof (T );
Var tp = new Type [objarr. Length];
For (int I = 0; I <objarr. Length; I ++)
{
Tp [I] = objarr [I]. GetType ();
}
Try
{
System. Reflection. ConstructorInfo ci = t. GetConstructor (tp );
M_instance = (T) ci. Invoke (objarr );
}
Catch
{
}
}
}
}
Return m_instance;
}
}