public
static
class
SingleInstanceFactory
{
private static Hashtable ht = new Hashtable();
private static object syncObject = new object ();
public static T GetSingleInstance < T > () where T : new ()
{
string key = typeof (T).ToString();
T t = default (T);
lock (syncObject)
{
if (ht.ContainsKey(key))
{
t = (T)ht[key];
}
else
{
lock (syncObject)
{
t = Activator.CreateInstance < T > ();
ht.Add(key, t);
}
}
}
return t;
}
}
{
private static Hashtable ht = new Hashtable();
private static object syncObject = new object ();
public static T GetSingleInstance < T > () where T : new ()
{
string key = typeof (T).ToString();
T t = default (T);
lock (syncObject)
{
if (ht.ContainsKey(key))
{
t = (T)ht[key];
}
else
{
lock (syncObject)
{
t = Activator.CreateInstance < T > ();
ht.Add(key, t);
}
}
}
return t;
}
}