1
|
|
|
2
|
|
#region Apache Notice
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
#endregion
|
26
|
|
|
27
|
|
#region Using
|
28
|
|
|
29
|
|
using System;
|
30
|
|
using System.Data;
|
31
|
|
using System.Globalization;
|
32
|
|
using System.Reflection;
|
33
|
|
using IBatisNet.Common.Utilities.Objects;
|
34
|
|
using IBatisNet.DataMapper.Configuration.ParameterMapping;
|
35
|
|
using IBatisNet.DataMapper.Configuration.ResultMapping;
|
36
|
|
using IBatisNet.DataMapper.Exceptions;
|
37
|
|
#endregion
|
38
|
|
|
39
|
|
|
40
|
|
|
41
|
|
namespace IBatisNet.DataMapper.TypeHandlers
|
42
|
|
{
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
internal class EnumTypeHandler : BaseTypeHandler
|
47
|
|
{
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
5
|
public override void SetParameter(IDataParameter dataParameter, object parameterValue, string dbType)
|
56
|
|
{
|
57
|
5
|
dataParameter.Value = Convert.ChangeType( parameterValue, Enum.GetUnderlyingType( parameterValue.GetType() ) );;
|
58
|
|
}
|
59
|
|
|
60
|
|
|
61
|
|
|
62
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66
|
12
|
public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
|
67
|
|
{
|
68
|
12
|
int index = dataReader.GetOrdinal(mapping.ColumnName);
|
69
|
|
|
70
|
12
|
if (dataReader.IsDBNull(index) == true)
|
71
|
|
{
|
72
|
1
|
return System.DBNull.Value;
|
73
|
|
}
|
74
|
|
else
|
75
|
|
{
|
76
|
11
|
return Enum.Parse(mapping.PropertyInfo.PropertyType, dataReader.GetValue(index).ToString());
|
77
|
|
}
|
78
|
|
}
|
79
|
|
|
80
|
0
|
public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
|
81
|
|
{
|
82
|
|
if (dataReader.IsDBNull(mapping.ColumnIndex) == true)
|
83
|
|
{
|
84
|
|
return System.DBNull.Value;
|
85
|
|
}
|
86
|
|
else
|
87
|
|
{
|
88
|
|
return Enum.Parse(mapping.PropertyInfo.PropertyType, dataReader.GetValue(mapping.ColumnIndex).ToString());
|
89
|
|
}
|
90
|
|
}
|
91
|
|
|
92
|
|
|
93
|
3
|
public override object ValueOf(Type type, string s)
|
94
|
|
{
|
95
|
3
|
return Enum.Parse(type, s);
|
96
|
|
}
|
97
|
|
|
98
|
0
|
public override object GetDataBaseValue(object outputValue, Type parameterType )
|
99
|
|
{
|
100
|
|
return Enum.Parse(parameterType, outputValue.ToString());
|
101
|
|
}
|
102
|
|
|
103
|
|
|
104
|
0
|
public override bool IsSimpleType
|
105
|
|
{
|
106
|
|
get
|
107
|
|
{
|
108
|
|
return true;
|
109
|
|
}
|
110
|
|
}
|
111
|
|
}
|
112
|
|
}
|
113
|
|
|