InternalOptionsRegistry.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Collections.Generic;
  3. using SRF.Service;
  4. namespace SRDebugger.Internal
  5. {
  6. /// <summary>
  7. /// Workaround for the debug panel not being initialized on startup.
  8. /// SROptions needs to register itself but not cause auto-initialization.
  9. /// This class buffers requests to register contains until there is a handler in place to deal with them.
  10. /// Once the handler is in place, all buffered requests are passed in and future requests invoke the handler directly.
  11. /// </summary>
  12. [Service(typeof(InternalOptionsRegistry))]
  13. public sealed class InternalOptionsRegistry
  14. {
  15. private List<object> _registeredContainers = new List<object>();
  16. private Action<object> _handler;
  17. public void AddOptionContainer(object obj)
  18. {
  19. if (_handler != null)
  20. {
  21. _handler(obj);
  22. return;
  23. }
  24. _registeredContainers.Add(obj);
  25. }
  26. public void SetHandler(Action<object> action)
  27. {
  28. _handler = action;
  29. foreach (object o in _registeredContainers)
  30. {
  31. _handler(o);
  32. }
  33. _registeredContainers = null;
  34. }
  35. }
  36. }