DropdownOption.cs 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. namespace Chronos.Controls.Editor
  2. {
  3. /// <summary>
  4. /// An option in an editor popup field.
  5. /// </summary>
  6. /// <typeparam name="T">The type of the backing value.</typeparam>
  7. public class DropdownOption<T>
  8. {
  9. /// <summary>
  10. /// The backing value of the option.
  11. /// </summary>
  12. public T value;
  13. /// <summary>
  14. /// The visible label of the option.
  15. /// </summary>
  16. public string label;
  17. /// <summary>
  18. /// Initializes a new instance of the PopupOption class with the specified value.
  19. /// </summary>
  20. public DropdownOption(T value)
  21. {
  22. this.value = value;
  23. this.label = value.ToString();
  24. }
  25. /// <summary>
  26. /// Initializes a new instance of the PopupOption class with the specified value and label.
  27. /// </summary>
  28. public DropdownOption(T value, string label)
  29. {
  30. this.value = value;
  31. this.label = label;
  32. }
  33. public static implicit operator T(DropdownOption<T> option)
  34. {
  35. return option.value;
  36. }
  37. }
  38. }