StationType.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Markup;
  7. namespace LocalhostMES.Enums
  8. {
  9. public enum StationType
  10. {
  11. OP10,
  12. OP20L,
  13. OP20R,
  14. OP30L,
  15. OP30R,
  16. OP40L,
  17. OP40R,
  18. OP50L,
  19. OP50R,
  20. OP60L,
  21. OP60R,
  22. OP70L,
  23. OP70R,
  24. OP80L,
  25. OP80R
  26. }
  27. public class EnumBindingSourceExtension : MarkupExtension
  28. {
  29. private Type _enumType;
  30. public Type EnumType
  31. {
  32. get => _enumType;
  33. set
  34. {
  35. if ( value != _enumType )
  36. {
  37. if ( null != value )
  38. {
  39. Type enumType = Nullable.GetUnderlyingType(value) ?? value;
  40. if ( !enumType.IsEnum )
  41. throw new ArgumentException("Type must be for an Enum.");
  42. }
  43. _enumType = value;
  44. }
  45. }
  46. }
  47. public EnumBindingSourceExtension() { }
  48. public EnumBindingSourceExtension(Type enumType)
  49. {
  50. EnumType = enumType;
  51. }
  52. public override object ProvideValue(IServiceProvider serviceProvider)
  53. {
  54. if ( null == _enumType )
  55. throw new InvalidOperationException("The EnumType must be specified.");
  56. Type actualEnumType = Nullable.GetUnderlyingType(_enumType) ?? _enumType;
  57. Array enumValues = Enum.GetValues(actualEnumType);
  58. if ( actualEnumType == _enumType )
  59. return enumValues;
  60. Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
  61. enumValues.CopyTo(tempArray, 1);
  62. return tempArray;
  63. }
  64. }
  65. }