OptionsServiceImpl.ReflectionOptionContainer.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using SRDebugger.Internal;
  4. namespace SRDebugger.Services.Implementation
  5. {
  6. public sealed partial class OptionsServiceImpl
  7. {
  8. /// <summary>
  9. /// Options container that is implemented via reflection.
  10. /// This is the normal behaviour used when options container is added as an `object`.
  11. /// </summary>
  12. private class ReflectionOptionContainer : IOptionContainer
  13. {
  14. // Options don't change, so just leave stubs that do nothing.
  15. public event Action<OptionDefinition> OptionAdded
  16. {
  17. add { }
  18. remove { }
  19. }
  20. public event Action<OptionDefinition> OptionRemoved
  21. {
  22. add { }
  23. remove { }
  24. }
  25. public bool IsDynamic
  26. {
  27. get { return false; }
  28. }
  29. private List<OptionDefinition> Options
  30. {
  31. get
  32. {
  33. if (_options == null) _options = SRDebuggerUtil.ScanForOptions(_target);
  34. return _options;
  35. }
  36. }
  37. private List<OptionDefinition> _options;
  38. public IEnumerable<OptionDefinition> GetOptions()
  39. {
  40. return Options;
  41. }
  42. private readonly object _target;
  43. public ReflectionOptionContainer(object target)
  44. {
  45. _target = target;
  46. }
  47. protected bool Equals(ReflectionOptionContainer other)
  48. {
  49. return Equals(other._target, this._target);
  50. }
  51. public override bool Equals(object obj)
  52. {
  53. if (ReferenceEquals(null, obj)) return false;
  54. if (ReferenceEquals(this, obj)) return true;
  55. if (obj.GetType() != this.GetType()) return false;
  56. return Equals((ReflectionOptionContainer) obj);
  57. }
  58. public override int GetHashCode()
  59. {
  60. return _target.GetHashCode();
  61. }
  62. }
  63. }
  64. }