版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

66 lines
2.3 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using ProductionControl.UI;
  9. namespace ProductionControl.UI.PropExtend
  10. {
  11. public class PropertySorter : ExpandableObjectConverter
  12. {
  13. #region Methods
  14. public override bool GetPropertiesSupported(ITypeDescriptorContext context)
  15. {
  16. return true;
  17. }
  18. public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
  19. {
  20. //
  21. // This override returns a list of properties in order
  22. //
  23. PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(value, attributes);
  24. ArrayList orderedProperties = new ArrayList();
  25. foreach (PropertyDescriptor pd in pdc)
  26. {
  27. Attribute attribute = pd.Attributes[typeof(PropertyOrderAttribute)];
  28. if (attribute != null)
  29. {
  30. //
  31. // If the attribute is found, then create an pair object to hold it
  32. //
  33. PropertyOrderAttribute poa = (PropertyOrderAttribute)attribute;
  34. orderedProperties.Add(new PropertyOrderPair(pd.Name, poa.Order));
  35. }
  36. else
  37. {
  38. //
  39. // If no order attribute is specifed then given it an order of 0
  40. //
  41. orderedProperties.Add(new PropertyOrderPair(pd.Name, 0));
  42. }
  43. }
  44. //
  45. // Perform the actual order using the value PropertyOrderPair classes
  46. // implementation of IComparable to sort
  47. //
  48. orderedProperties.Sort();
  49. //
  50. // Build a string list of the ordered names
  51. //
  52. ArrayList propertyNames = new ArrayList();
  53. foreach (PropertyOrderPair pop in orderedProperties)
  54. {
  55. propertyNames.Add(pop.Name);
  56. }
  57. //
  58. // Pass in the ordered list for the PropertyDescriptorCollection to sort by
  59. //
  60. return pdc.Sort((string[])propertyNames.ToArray(typeof(string)));
  61. }
  62. #endregion
  63. }
  64. }