You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

29 lines
844 B

namespace Asset_Cleaner {
static class Globals<T> where T : class {
static T _instance;
public static T Value {
get {
Asr.IsFalse(_instance == null);
return _instance;
}
set {
var was = HasValue();
_instance = value;
// keep counter to check during deinitialization if all Globals are cleared
if (was && !HasValue())
__GlobalsCounter.Counter -= 1;
if (!was && HasValue())
__GlobalsCounter.Counter += 1;
bool HasValue() => _instance != null;
}
}
}
static class __GlobalsCounter {
internal static int Counter;
public static bool HasAnyValue() => Counter > 0;
}
}