diff options
Diffstat (limited to '')
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs (renamed from ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs) | 140 |
1 files changed, 69 insertions, 71 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs index 89bc0f0..20d8cf1 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs | |||
@@ -30,17 +30,15 @@ using System.Data.Common; | |||
30 | 30 | ||
31 | namespace TribalMedia.Framework.Data | 31 | namespace TribalMedia.Framework.Data |
32 | { | 32 | { |
33 | public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); | 33 | //public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); |
34 | 34 | //public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); | |
35 | public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); | ||
36 | 35 | ||
37 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); | 36 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); |
38 | |||
39 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); | 37 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); |
40 | 38 | ||
41 | public abstract class FieldMapper | 39 | public abstract class BaseFieldMapper |
42 | { | 40 | { |
43 | private readonly TableMapper m_tableMapper; | 41 | private readonly BaseTableMapper m_tableMapper; |
44 | private readonly string m_fieldName; | 42 | private readonly string m_fieldName; |
45 | 43 | ||
46 | public string FieldName | 44 | public string FieldName |
@@ -57,7 +55,7 @@ namespace TribalMedia.Framework.Data | |||
57 | 55 | ||
58 | public abstract object GetParamValue(object obj); | 56 | public abstract object GetParamValue(object obj); |
59 | 57 | ||
60 | public FieldMapper( TableMapper tableMapper, string fieldName, Type valueType) | 58 | public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType) |
61 | { | 59 | { |
62 | m_fieldName = fieldName; | 60 | m_fieldName = fieldName; |
63 | m_valueType = valueType; | 61 | m_valueType = valueType; |
@@ -94,32 +92,32 @@ namespace TribalMedia.Framework.Data | |||
94 | { | 92 | { |
95 | value = reader.GetGuid(m_fieldName); | 93 | value = reader.GetGuid(m_fieldName); |
96 | } | 94 | } |
97 | else if (ValueType == typeof (bool)) | 95 | else if (ValueType == typeof(bool)) |
98 | { | 96 | { |
99 | uint boolVal = reader.GetUShort(m_fieldName); | 97 | uint boolVal = reader.GetUShort(m_fieldName); |
100 | value = (boolVal == 1); | 98 | value = (boolVal == 1); |
101 | } | 99 | } |
102 | else | ||
103 | if (ValueType == typeof (byte)) | ||
104 | { | ||
105 | value = reader.GetByte(m_fieldName); | ||
106 | } | ||
107 | else if (ValueType == typeof (sbyte)) | ||
108 | { | ||
109 | value = reader.GetSByte(m_fieldName); | ||
110 | } | ||
111 | else if (ValueType == typeof (ushort)) | ||
112 | { | ||
113 | value = reader.GetUShort(m_fieldName); | ||
114 | } | ||
115 | else if (ValueType == typeof (byte[])) | ||
116 | { | ||
117 | value = reader.GetBytes(m_fieldName); | ||
118 | } | ||
119 | else | 100 | else |
120 | { | 101 | if (ValueType == typeof(byte)) |
121 | value = reader.Get(m_fieldName); | 102 | { |
122 | } | 103 | value = reader.GetByte(m_fieldName); |
104 | } | ||
105 | else if (ValueType == typeof(sbyte)) | ||
106 | { | ||
107 | value = reader.GetSByte(m_fieldName); | ||
108 | } | ||
109 | else if (ValueType == typeof(ushort)) | ||
110 | { | ||
111 | value = reader.GetUShort(m_fieldName); | ||
112 | } | ||
113 | else if (ValueType == typeof(byte[])) | ||
114 | { | ||
115 | value = reader.GetBytes(m_fieldName); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | value = reader.Get(m_fieldName); | ||
120 | } | ||
123 | 121 | ||
124 | if (value is DBNull) | 122 | if (value is DBNull) |
125 | { | 123 | { |
@@ -130,51 +128,51 @@ namespace TribalMedia.Framework.Data | |||
130 | } | 128 | } |
131 | } | 129 | } |
132 | 130 | ||
133 | public class RowMapperField<TRowMapper, TField> : FieldMapper | 131 | //public class RowMapperField<TRowMapper, TField> : FieldMapper |
134 | where TRowMapper : RowMapper | 132 | // where TRowMapper : RowMapper |
135 | { | 133 | //{ |
136 | private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; | 134 | // private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; |
137 | private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; | 135 | // private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; |
138 | 136 | ||
139 | public override object GetParamValue(object obj) | 137 | // public override object GetParamValue(object obj) |
140 | { | 138 | // { |
141 | return m_fieldGetAccessor((TRowMapper) obj); | 139 | // return m_fieldGetAccessor((TRowMapper) obj); |
142 | } | 140 | // } |
143 | 141 | ||
144 | public override void SetPropertyFromReader(object mapper, DataReader reader) | 142 | // public override void SetPropertyFromReader(object mapper, DataReader reader) |
145 | { | 143 | // { |
146 | object value; | 144 | // object value; |
147 | 145 | ||
148 | value = GetValue(reader); | 146 | // value = GetValue(reader); |
149 | 147 | ||
150 | if (value == null) | 148 | // if (value == null) |
151 | { | 149 | // { |
152 | m_fieldSetAccessor((TRowMapper) mapper, default(TField)); | 150 | // m_fieldSetAccessor((TRowMapper) mapper, default(TField)); |
153 | } | 151 | // } |
154 | else | 152 | // else |
155 | { | 153 | // { |
156 | m_fieldSetAccessor((TRowMapper) mapper, (TField) value); | 154 | // m_fieldSetAccessor((TRowMapper) mapper, (TField) value); |
157 | } | 155 | // } |
158 | } | 156 | // } |
159 | 157 | ||
160 | 158 | ||
161 | public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, | 159 | // public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, |
162 | RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) | 160 | // RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) |
163 | : base(tableMapper, fieldName, typeof(TField)) | 161 | // : base(tableMapper, fieldName, typeof(TField)) |
164 | { | 162 | // { |
165 | m_fieldGetAccessor = rowMapperGetAccessor; | 163 | // m_fieldGetAccessor = rowMapperGetAccessor; |
166 | m_fieldSetAccessor = rowMapperSetAccessor; | 164 | // m_fieldSetAccessor = rowMapperSetAccessor; |
167 | } | 165 | // } |
168 | } | 166 | //} |
169 | 167 | ||
170 | public class ObjectField<TObject, TField> : FieldMapper | 168 | public class ObjectField<TObject, TField> : BaseFieldMapper |
171 | { | 169 | { |
172 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; | 170 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; |
173 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; | 171 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; |
174 | 172 | ||
175 | public override object GetParamValue(object obj) | 173 | public override object GetParamValue(object obj) |
176 | { | 174 | { |
177 | return m_fieldGetAccessor((TObject) obj); | 175 | return m_fieldGetAccessor((TObject)obj); |
178 | } | 176 | } |
179 | 177 | ||
180 | public override void SetPropertyFromReader(object obj, DataReader reader) | 178 | public override void SetPropertyFromReader(object obj, DataReader reader) |
@@ -185,18 +183,18 @@ namespace TribalMedia.Framework.Data | |||
185 | 183 | ||
186 | if (value == null) | 184 | if (value == null) |
187 | { | 185 | { |
188 | m_fieldSetAccessor((TObject) obj, default(TField)); | 186 | m_fieldSetAccessor((TObject)obj, default(TField)); |
189 | } | 187 | } |
190 | else | 188 | else |
191 | { | 189 | { |
192 | m_fieldSetAccessor((TObject) obj, (TField) value); | 190 | m_fieldSetAccessor((TObject)obj, (TField)value); |
193 | } | 191 | } |
194 | } | 192 | } |
195 | 193 | ||
196 | 194 | ||
197 | public ObjectField(TableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, | 195 | public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, |
198 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) | 196 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) |
199 | : base(tableMapper, fieldName, typeof (TField)) | 197 | : base(tableMapper, fieldName, typeof(TField)) |
200 | { | 198 | { |
201 | m_fieldGetAccessor = rowMapperGetAccessor; | 199 | m_fieldGetAccessor = rowMapperGetAccessor; |
202 | m_fieldSetAccessor = rowMapperSetAccessor; | 200 | m_fieldSetAccessor = rowMapperSetAccessor; |