apieceoffruit

Untitled

Apr 8th, 2021
443
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     public class FlagChecker
  3.     {
  4.         readonly Dictionary<string, bool> _flags = new Dictionary<string, bool>();
  5.  
  6.         public void Set(string flag, bool val)
  7.         {
  8.             OnFlagSet(flag, _flags[flag], val);
  9.             _flags[flag] = val;
  10.         }
  11.  
  12.         void OnFlagSet(string flag, bool old, bool newVal)
  13.         {
  14.             OnFlagChanged(flag,newVal);
  15.         }
  16.  
  17.         public bool IsTrue(string flag) => _flags[flag];
  18.         public bool IsFalse(string flag) => !_flags[flag];
  19.        
  20.         public bool this[string flag]
  21.         {
  22.             get => _flags[flag];
  23.             set => SetFalse(flag);
  24.         }
  25.  
  26.         public void SetTrue(string flag) => Set(flag,true);
  27.         public void SetFalse(string flag) => Set(flag, false);
  28.  
  29.         public event Action<string, bool> FlagChanged;
  30.         public event Action<string> FlagTrue;
  31.         public event Action<string> FlagFalse;
  32.        
  33.         protected virtual void OnFlagChanged(string flag, bool val)
  34.         {
  35.             FlagChanged?.Invoke(flag, val);
  36.             if (val) OnFlagTrue(flag);
  37.             else OnFlagFalse(flag);
  38.         }
  39.  
  40.         protected virtual void OnFlagTrue(string obj) => FlagTrue?.Invoke(obj);
  41.  
  42.         protected virtual void OnFlagFalse(string obj) => FlagFalse?.Invoke(obj);
  43.     }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×