1 using system;
2 using system.collections;
3 using system.collections.generic;
4 using system.reflection;
5
6 namespace xxware.xxcontrols
7 {
8 public class reverser : icomparer
9 {
10 private type _type = null;
11 private reverserinfo info;
12
13 ///
14 /// 构造函数
15 ///
16 /// 进行比较的类类型
17 /// 进行比较对象的属性名称
18 /// 比较方向(升序/降序)
19 public reverser(type _type, string _name, string _direction)
20 {
21 this._type = _type;
22 this.info.name = _name;
23 this.info.direction = _direction.tolower();
24 }
25
26 ///
27 /// 构造函数
28 ///
29 /// 进行比较的类名称
30 /// 进行比较对象的属性名称
31 /// 比较方向(升序/降序)
32 public reverser(string _classname, string _name, string _direction)
33 {
34 try
35 {
36 this._type = type.gettype(_classname, true);
37 this.info.name = _name;
38 this.info.direction = _direction.tolower();
39 }
40
catch (exception e)
41 {
42 throw new exception(e.message);
43 }
44
45 }
46
47 ///
48 /// 构造函数
49 ///
50 /// 进行比较的类型的实例
51 /// 进行比较对象的属性名称
52 /// 比较方向(升序/降序)
53 public reverser(t _t, string _name, string _direction)
54 {
55 this._type = _t.gettype();
56 this.info.name = _name;
57 this.info.direction = _direction;
58 }
59
60 int icomparer.compare(t t1, t t2)
61 {
62 object x = this._type.invokemember(this.info.name, bindingflags.public | bindingflags.instance | bindingflags.getproperty, null, t1, null);
63 object y = this._type.invokemember(this.info.name, bindingflags.public | bindingflags.instance | bindingflags.getproperty, null, t2, null);
64
65 if (this.info.direction != "asc")
66 swap(ref x, ref y);
67 return (new caseinsensitivecomparer()).compare(x, y);
68 }
69
70 void swap(ref object x, ref object y)
71 {
72 object tmp = x;
73 x = y;
74 y = tmp;
75 }
76 }
77 public struct reverserinfo
78 {
79 public enum target
80 {
81 customer = 0,
82 from,
83 field,
84 server
85 }
86
87 public string name;
88 public string direction; // asc , desc ;
89 public target target;
90 }
91 }代码2: template类,用于生成checkbox列