-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSingleton.cs
27 lines (25 loc) · 943 Bytes
/
Singleton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SALT
{
/// <summary>
/// Makes a singleton class, said class will only allow a single instance of itself
/// </summary>
/// <typeparam name="T">The type of the class turned into a singleton</typeparam>
public abstract class Singleton<T> where T : Singleton<T>
{
/// <summary>The instance of this singleton</summary>
public static T Instance { get; private set; }
/// <summary>The constructor that sets the instance value</summary>
protected Singleton()
{
if ((object)Singleton<T>.Instance != null)
Console.Console.LogWarning(string.Format("Trying to create a new instance of {0} while there can only be one!", (object)this.GetType()));
else
Singleton<T>.Instance = (T)this;
}
}
}