duheng
2024-07-22 8e244c142fcc849de0e8c0a12693976b27927b9e
WinFrmUI/Yw.WinFrmUI.Core/07-sorter/PropertySorter.cs
ÎļþÃû´Ó WinFrmUI/HStation.WinFrmUI.Xhs.Core/03-ViewModel/PropertySorter.cs ÐÞ¸Ä
@@ -1,18 +1,31 @@
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)
        {
            //
@@ -44,6 +57,8 @@
            // implementation of IComparable to sort
            //
            orderedProperties.Sort();
            //
            // Build a string list of the ordered names
            //
@@ -57,12 +72,13 @@
            //
            return pdc.Sort((string[])propertyNames.ToArray(typeof(string)));
        }
        #endregion Methods
        #endregion
    }
    #region Helper Class - PropertyOrderAttribute
    /// <summary>
    ///
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class PropertyOrderAttribute : Attribute
    {
@@ -70,12 +86,14 @@
        // 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
@@ -84,16 +102,21 @@
            }
        }
    }
    #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
@@ -101,13 +124,20 @@
                return _name;
            }
        }
        private string _name;
        /// <summary>
        ///
        /// </summary>
        public PropertyOrderPair(string name, int order)
        {
            _order = order;
            _name = name;
        }
        /// <summary>
        ///
        /// </summary>
        public int CompareTo(object obj)
        {
            //
@@ -130,6 +160,8 @@
            return 1;
        }
    }
    #endregion
    #endregion Helper Class - PropertyOrderPair
}
}