OSDN Git Service

na-get-lib,ひとまず依存関係解決関数群を作った。
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / ListViewItemSortComparer.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 using NaGet.Packages;\r
5 using NaGet.Packages.Install;\r
6 using System.IO;\r
7 using System.Collections.Generic;\r
8 \r
9 namespace AppliStation.Util\r
10 {\r
11         /// <summary>\r
12         /// ListViewのソートをカプセル化するためのクラス\r
13         /// </summary>\r
14         class ListViewItemSortComparer : System.Collections.IComparer\r
15         {\r
16                 /// <summary>\r
17                 /// ソートの方向。昇順か?降順か?\r
18                 /// </summary>\r
19                 public SortOrder Order = SortOrder.Ascending;\r
20                 \r
21                 /// <summary>\r
22                 /// ソート対象のコラムインデックス\r
23                 /// </summary>\r
24                 public int Column = -1;\r
25                 \r
26                 /// <summary>\r
27                 /// コンストラクタ\r
28                 /// </summary>\r
29                 /// <param name="index">ソート対象のコラムインデックス</param>\r
30                 /// <param name="order">ソートの方向。昇順か?降順か?</param>\r
31                 public ListViewItemSortComparer(int index, SortOrder order)\r
32                 {\r
33                         this.Column = index;\r
34                         this.Order = order;\r
35                 }\r
36                 \r
37                 public int Compare(object x, object y)\r
38                 {\r
39                         ListViewItem itemx = (ListViewItem) x;\r
40                         ListViewItem itemy = (ListViewItem) y;\r
41                         \r
42                         int result = -1;\r
43                         result = string.Compare(itemx.SubItems[Column].Text,\r
44                                                 itemy.SubItems[Column].Text);\r
45                         \r
46                         switch (Order) {\r
47                                 case SortOrder.Descending:\r
48                                         result =  -result;\r
49                                         break;\r
50                                 case SortOrder.None:\r
51                                         result = 0;\r
52                                         break;\r
53                         }\r
54                         return result;\r
55                 }\r
56         }\r
57 }\r