ÎļþÃû´Ó WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-ViewModel/PropertySorter.cs ÐÞ¸Ä |
| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | |
| | | namespace HStation.WinFrmUI.Core |
| | | namespace Yw.WinFrmUI |
| | | { |
| | | /// <summary> |
| | | /// 屿§æåº |
| | | /// </summary> |
| | | public class PropertySorter : ExpandableObjectConverter |
| | | { |
| | | #region Methods |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public override bool GetPropertiesSupported(ITypeDescriptorContext context) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) |
| | | { |
| | | // |
| | |
| | | // implementation of IComparable to sort |
| | | // |
| | | orderedProperties.Sort(); |
| | | |
| | | |
| | | // |
| | | // Build a string list of the ordered names |
| | | // |
| | |
| | | // |
| | | return pdc.Sort((string[])propertyNames.ToArray(typeof(string))); |
| | | } |
| | | |
| | | #endregion Methods |
| | | #endregion |
| | | } |
| | | |
| | | #region Helper Class - PropertyOrderAttribute |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | [AttributeUsage(AttributeTargets.Property)] |
| | | public class PropertyOrderAttribute : Attribute |
| | | { |
| | |
| | | // Simple attribute to allow the order of a property to be specified |
| | | // |
| | | private int _order; |
| | | |
| | | public PropertyOrderAttribute(int order) |
| | | { |
| | | _order = order; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public int Order |
| | | { |
| | | get |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion Helper Class - PropertyOrderAttribute |
| | | #endregion |
| | | |
| | | #region Helper Class - PropertyOrderPair |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public class PropertyOrderPair : IComparable |
| | | { |
| | | private int _order; |
| | | private string _name; |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public string Name |
| | | { |
| | | get |
| | |
| | | return _name; |
| | | } |
| | | } |
| | | private string _name; |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public PropertyOrderPair(string name, int order) |
| | | { |
| | | _order = order; |
| | | _name = name; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public int CompareTo(object obj) |
| | | { |
| | | // |
| | |
| | | return 1; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #endregion Helper Class - PropertyOrderPair |
| | | } |
| | | |
| | | |
| | | } |