1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Collections;
|
21
|
|
using System.Data;
|
22
|
|
using Seasar.Framework.Util;
|
23
|
|
|
24
|
|
namespace Seasar.Extension.Unit
|
25
|
|
{
|
26
|
|
public class DictionaryReader : Seasar.Extension.DataSets.IDataReader
|
27
|
|
{
|
28
|
|
private DataSet dataSet_;
|
29
|
|
|
30
|
|
private DataTable table_;
|
31
|
|
|
32
|
2
|
public DictionaryReader() : this(null)
|
33
|
|
{
|
34
|
|
}
|
35
|
|
|
36
|
9
|
public DictionaryReader(IDictionary dictionary)
|
37
|
|
{
|
38
|
9
|
dataSet_ = new DataSet();
|
39
|
9
|
table_ = dataSet_.Tables.Add("Map");
|
40
|
|
|
41
|
9
|
if (dictionary != null)
|
42
|
|
{
|
43
|
7
|
SetupColumns(dictionary);
|
44
|
7
|
SetupRow(dictionary);
|
45
|
|
}
|
46
|
|
}
|
47
|
|
|
48
|
9
|
protected void SetupColumns(IDictionary dictionary)
|
49
|
|
{
|
50
|
9
|
foreach (string key in dictionary.Keys)
|
51
|
|
{
|
52
|
74
|
object value = dictionary[key];
|
53
|
74
|
if (value != null)
|
54
|
|
{
|
55
|
73
|
Type type = PropertyUtil.GetPrimitiveType(value.GetType());
|
56
|
73
|
table_.Columns.Add(key, type);
|
57
|
|
}
|
58
|
|
else
|
59
|
|
{
|
60
|
1
|
table_.Columns.Add(key);
|
61
|
|
}
|
62
|
|
}
|
63
|
|
}
|
64
|
|
|
65
|
9
|
protected void SetupRow(IDictionary dictionary)
|
66
|
|
{
|
67
|
9
|
DataRow row = table_.NewRow();
|
68
|
9
|
foreach (DataColumn column in table_.Columns)
|
69
|
|
{
|
70
|
74
|
object value = dictionary[column.ColumnName];
|
71
|
74
|
row[column.ColumnName] = PropertyUtil.GetPrimitiveValue(value);
|
72
|
|
}
|
73
|
9
|
table_.Rows.Add(row);
|
74
|
9
|
row.AcceptChanges();
|
75
|
|
}
|
76
|
|
|
77
|
|
#region IDataReader メンバ
|
78
|
|
|
79
|
9
|
public DataSet Read()
|
80
|
|
{
|
81
|
9
|
return dataSet_;
|
82
|
|
}
|
83
|
|
|
84
|
|
#endregion
|
85
|
|
}
|
86
|
|
}
|
87
|
|
|