-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d77d1cb
commit 99d6473
Showing
10 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
namespace CO; | ||
using LoadOrderTool; | ||
using System; | ||
|
||
namespace CO { | ||
public abstract class SingletonLite<T> where T : new() { | ||
protected static T sInstance; | ||
private static object lockObject = new object(); | ||
public static T instance { | ||
get { | ||
public abstract class SingletonLite<T> | ||
where T : SingletonLite<T>, new() { | ||
protected static T sInstance; | ||
private static object lockObject = new object(); // work around in case constructor was used by mistake. | ||
public static T instance { | ||
get { | ||
try { | ||
if (sInstance == null) { | ||
lock (lockObject) { | ||
sInstance = new T(); | ||
Log.Debug("Creating singleton of type " + typeof(T).Name); | ||
Log.Debug("Created singleton of type " + typeof(T).Name + ". calling Awake() ..."); | ||
sInstance.Awake(); | ||
Log.Debug("Awake() finished for " + typeof(T).Name); | ||
} | ||
} | ||
return sInstance; | ||
} catch(Exception ex) { | ||
ex.Log(); | ||
throw; | ||
} | ||
} | ||
} | ||
|
||
public static bool exists => sInstance != null; | ||
public static bool exists => sInstance != null; | ||
|
||
public static void Ensure() => _ = instance; | ||
} | ||
public static void Ensure() => _ = instance; | ||
public virtual void Awake() { } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters