描述数据列的类定义
定义ColumnCollection
下一篇,我们终于可以定义Table了
1 /// <summary>
2 /// 描述数据列
3 /// </summary>
4 public class Column
5 {
6
7
8 public Column(string name, Type type)
9 : this(name, type, null)
10 {
11
12 }
13
14 public Column(string name, Type type,object defaultValue)
15 {
16 ColumnName = name;
17 DataType = type;
18 DefaultValue = defaultValue;
19 }
20
21 /// <summary>
22 /// 获取或设置列的名称
23 /// </summary>
24 public readonly string ColumnName;
25 /// <summary>
26 /// 获取或设置列的数据类型
27 /// </summary>
28 public readonly System.Type DataType;
29 /// <summary>
30 /// 获取或设置列的默认值
31 /// </summary>
32 public object DefaultValue = null;
33
34
35 }
2 /// 描述数据列
3 /// </summary>
4 public class Column
5 {
6
7
8 public Column(string name, Type type)
9 : this(name, type, null)
10 {
11
12 }
13
14 public Column(string name, Type type,object defaultValue)
15 {
16 ColumnName = name;
17 DataType = type;
18 DefaultValue = defaultValue;
19 }
20
21 /// <summary>
22 /// 获取或设置列的名称
23 /// </summary>
24 public readonly string ColumnName;
25 /// <summary>
26 /// 获取或设置列的数据类型
27 /// </summary>
28 public readonly System.Type DataType;
29 /// <summary>
30 /// 获取或设置列的默认值
31 /// </summary>
32 public object DefaultValue = null;
33
34
35 }
定义ColumnCollection
1 /// <summary>
2 /// 描述或设置列的集合
3 /// </summary>
4 public class ColumnCollection : System.Collections.CollectionBase
5 {
6 /// <summary>
7 /// 设置或获取指定的列
8 /// </summary>
9 /// <param name="index"></param>
10 /// <returns></returns>
11 public Column this[int index]
12 {
13 get
14 {
15 return (Column)this.InnerList[index];
16 }
17 set
18 {
19 this.InnerList[index] = value;
20 }
21 }
22
23 /// <summary>
24 /// 设置或获取指定的列
25 /// </summary>
26 /// <param name="index"></param>
27 /// <returns></returns>
28 public Column this[string columnName]
29 {
30 get
31 {
32 return (Column)this[this.IndexOf(columnName)];
33 }
34 set
35 {
36 this[this.IndexOf(columnName)] = value;
37 }
38 }
39
40 private System.Collections.ArrayList colNames=new System.Collections.ArrayList();
41
42 /// <summary>
43 /// 添加一个列
44 /// </summary>
45 /// <param name="column">列的实例</param>
46 public void Add(Column column)
47 {
48 if(!colNames.Contains(column.ColumnName))
49 {
50 this.InnerList.Add(column);
51 colNames.Add(column.ColumnName);
52 }
53
54 }
55
56 /// <summary>
57 /// 添加一个列
58 /// </summary>
59 /// <param name="name">列的名称</param>
60 /// <param name="type">列的类型</param>
61 public void Add(string name, Type type, object defaultValue)
62 {
63 this.Add(new Column(name, type,defaultValue));
64 }
65
66 /// <summary>
67 /// 返回列的名称是否包含在集合中
68 /// </summary>
69 /// <param name="columnName">列的名称</param>
70 /// <returns>如果已经包含,则返回true,否则为false</returns>
71 public bool Contains(string columnName)
72 {
73 return colNames.Contains(colNames);
74 }
75
76 /// <summary>
77 /// 返回列的位置
78 /// </summary>
79 /// <param name="column">列的实例</param>
80 /// <returns>如果没有包含则返回-1,否则从0开始的索引</returns>
81 public int IndexOf(Column column)
82 {
83 return this.IndexOf(column.ColumnName);
84 }
85
86 /// <summary>
87 /// 返回列的位置
88 /// </summary>
89 /// <param name="column">列的实例</param>
90 /// <returns>如果没有包含则返回-1,否则从0开始的索引</returns>
91 public int IndexOf(string columnName)
92 {
93 return colNames.IndexOf(columnName);
94 }
95 }
2 /// 描述或设置列的集合
3 /// </summary>
4 public class ColumnCollection : System.Collections.CollectionBase
5 {
6 /// <summary>
7 /// 设置或获取指定的列
8 /// </summary>
9 /// <param name="index"></param>
10 /// <returns></returns>
11 public Column this[int index]
12 {
13 get
14 {
15 return (Column)this.InnerList[index];
16 }
17 set
18 {
19 this.InnerList[index] = value;
20 }
21 }
22
23 /// <summary>
24 /// 设置或获取指定的列
25 /// </summary>
26 /// <param name="index"></param>
27 /// <returns></returns>
28 public Column this[string columnName]
29 {
30 get
31 {
32 return (Column)this[this.IndexOf(columnName)];
33 }
34 set
35 {
36 this[this.IndexOf(columnName)] = value;
37 }
38 }
39
40 private System.Collections.ArrayList colNames=new System.Collections.ArrayList();
41
42 /// <summary>
43 /// 添加一个列
44 /// </summary>
45 /// <param name="column">列的实例</param>
46 public void Add(Column column)
47 {
48 if(!colNames.Contains(column.ColumnName))
49 {
50 this.InnerList.Add(column);
51 colNames.Add(column.ColumnName);
52 }
53
54 }
55
56 /// <summary>
57 /// 添加一个列
58 /// </summary>
59 /// <param name="name">列的名称</param>
60 /// <param name="type">列的类型</param>
61 public void Add(string name, Type type, object defaultValue)
62 {
63 this.Add(new Column(name, type,defaultValue));
64 }
65
66 /// <summary>
67 /// 返回列的名称是否包含在集合中
68 /// </summary>
69 /// <param name="columnName">列的名称</param>
70 /// <returns>如果已经包含,则返回true,否则为false</returns>
71 public bool Contains(string columnName)
72 {
73 return colNames.Contains(colNames);
74 }
75
76 /// <summary>
77 /// 返回列的位置
78 /// </summary>
79 /// <param name="column">列的实例</param>
80 /// <returns>如果没有包含则返回-1,否则从0开始的索引</returns>
81 public int IndexOf(Column column)
82 {
83 return this.IndexOf(column.ColumnName);
84 }
85
86 /// <summary>
87 /// 返回列的位置
88 /// </summary>
89 /// <param name="column">列的实例</param>
90 /// <returns>如果没有包含则返回-1,否则从0开始的索引</returns>
91 public int IndexOf(string columnName)
92 {
93 return colNames.IndexOf(columnName);
94 }
95 }
下一篇,我们终于可以定义Table了