UsersCollection.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:1k
- using System;
- using System.Collections;
- namespace qminoa.BLL.PM
- {
- public class UsersCollection : ArrayList
- {
- public enum UserFields
- {
- InitValue,
- UserName,
- RoleName
- }
- public void Sort(UserFields sortField, bool isAscending)
- {
- switch (sortField)
- {
- case UserFields.UserName:
- base.Sort(new NameComparer());
- break;
- case UserFields.RoleName:
- base.Sort(new RoleNameComparer());
- break;
- }
- if (!isAscending) base.Reverse();
- }
- private sealed class NameComparer : IComparer
- {
- public int Compare(object x, object y)
- {
- PMUser first = (PMUser) x;
- PMUser second = (PMUser) y;
- return first.UserName.CompareTo(second.UserName);
- }
- }
- private sealed class RoleNameComparer : IComparer
- {
- public int Compare(object x, object y)
- {
- PMUser first = (PMUser) x;
- PMUser second = (PMUser) y;
- return first.RoleName.CompareTo(second.RoleName);
- }
- }
- }
- }