EnumParameter.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. namespace WingServerCommon.Config.Parameters
  5. { /// <summary>
  6. /// Enum parameter base type
  7. /// </summary>
  8. /// <typeparam name="T"></typeparam>
  9. [DataContract]
  10. public abstract class EnumParameterBase<T> : IParameter
  11. {
  12. private T _initialValue;
  13. private T _value;
  14. /// <summary>
  15. /// parameter value
  16. /// </summary>
  17. [DataMember]
  18. public IList<T> Source { get; set; }
  19. public T InitialValue => _initialValue;
  20. /// <summary>
  21. /// parameter value
  22. /// </summary>
  23. [DataMember]
  24. public T Value
  25. {
  26. get => _value;
  27. set
  28. {
  29. if (!Equals(_value, value))
  30. {
  31. _value = value;
  32. OnValueChanged();
  33. }
  34. }
  35. }
  36. /// <summary>
  37. /// parameter name
  38. /// </summary>
  39. public string Name { get; set; }
  40. /// <summary>
  41. /// parameter section
  42. /// </summary>
  43. public string Section { get; set; }
  44. /// <summary>
  45. /// parameter value changed state
  46. /// </summary>
  47. public bool IsChanged => !Equals(_initialValue, Value);
  48. /// <summary>
  49. /// value changed event
  50. /// </summary>
  51. public event EventHandler ValueChanged;
  52. /// <summary>
  53. /// notify value changed
  54. /// </summary>
  55. private void OnValueChanged()
  56. {
  57. ValueChanged?.Invoke(this, EventArgs.Empty);
  58. }
  59. /// <summary>
  60. /// change initial value
  61. /// </summary>
  62. public void ChangeInitialValue()
  63. {
  64. _initialValue = Value;
  65. }
  66. /// <summary>
  67. /// Set user value;
  68. /// </summary>
  69. /// <param name="value">User setting value.</param>
  70. public abstract void ChangeParameterValue(object value);
  71. }
  72. }