Files
spark/src/client/spark_core/VirtualSingleton.cs
T

21 lines
614 B
C#

#nullable enable
namespace Spark.Core {
using bts;
using System.Threading;
/// <summary>
/// A (base) class that asserts it isn't instantiated more than once
/// </summary>
/// <typeparam name="T">
/// The underlying type, which is prevented from being instantiated more than once, as it
/// inherits from <see cref="VirtualSingleton{T}"/> itself
/// </typeparam>
public abstract class VirtualSingleton<T> where T : VirtualSingleton<T> {
static int _instances = 0;
protected VirtualSingleton() =>
Log.assert(Interlocked.Increment(ref _instances) == 1);
}
}