Mercurial > pub > bltoolkit
comparison Source/Reflection/ExprMemberAccessor.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f990fcb411a9 |
---|---|
1 using System; | |
2 using System.Data.SqlTypes; | |
3 using System.Linq.Expressions; | |
4 using System.Reflection; | |
5 using System.Reflection.Emit; | |
6 | |
7 namespace BLToolkit.Reflection | |
8 { | |
9 using Common; | |
10 using Emit; | |
11 | |
12 public abstract class ExprMemberAccessor : MemberAccessor | |
13 { | |
14 protected ExprMemberAccessor(TypeAccessor typeAccessor, MemberInfo memberInfo) | |
15 : base(typeAccessor, memberInfo) | |
16 { | |
17 } | |
18 | |
19 #region Public Properties | |
20 | |
21 protected bool HasSetterValue; | |
22 public override bool HasGetter { get { return true; } } | |
23 public override bool HasSetter { get { return HasSetterValue; } } | |
24 | |
25 #endregion | |
26 | |
27 static public MemberAccessor GetMemberAccessor(TypeAccessor typeAccessor, string memberName) | |
28 { | |
29 var par = Expression.Parameter(typeof(object), "obj"); | |
30 var expr = Expression.PropertyOrField(Expression.Convert(par, typeAccessor.Type), memberName); | |
31 | |
32 var type = expr.Type; | |
33 | |
34 var underlyingType = type; | |
35 var isNullable = false; | |
36 | |
37 if (underlyingType.IsGenericType && underlyingType.GetGenericTypeDefinition() == typeof(Nullable<>)) | |
38 { | |
39 underlyingType = underlyingType.GetGenericArguments()[0]; | |
40 isNullable = true; | |
41 } | |
42 | |
43 if (underlyingType.IsEnum) | |
44 underlyingType = Enum.GetUnderlyingType(underlyingType); | |
45 | |
46 if (isNullable) | |
47 { | |
48 switch (Type.GetTypeCode(underlyingType)) | |
49 { | |
50 case TypeCode.Boolean : return new NullableBooleanAccessor (typeAccessor, par, expr); | |
51 case TypeCode.Char : return new NullableCharAccessor (typeAccessor, par, expr); | |
52 case TypeCode.SByte : return new NullableSByteAccessor (typeAccessor, par, expr); | |
53 case TypeCode.Byte : return new NullableByteAccessor (typeAccessor, par, expr); | |
54 case TypeCode.Int16 : return new NullableInt16Accessor (typeAccessor, par, expr); | |
55 case TypeCode.UInt16 : return new NullableUInt16Accessor (typeAccessor, par, expr); | |
56 case TypeCode.Int32 : return new NullableInt32Accessor (typeAccessor, par, expr); | |
57 case TypeCode.UInt32 : return new NullableUInt32Accessor (typeAccessor, par, expr); | |
58 case TypeCode.Int64 : return new NullableInt64Accessor (typeAccessor, par, expr); | |
59 case TypeCode.UInt64 : return new NullableUInt64Accessor (typeAccessor, par, expr); | |
60 case TypeCode.Single : return new NullableSingleAccessor (typeAccessor, par, expr); | |
61 case TypeCode.Double : return new NullableDoubleAccessor (typeAccessor, par, expr); | |
62 case TypeCode.Decimal : return new NullableDecimalAccessor (typeAccessor, par, expr); | |
63 case TypeCode.DateTime : return new NullableDateTimeAccessor(typeAccessor, par, expr); | |
64 case TypeCode.Object : | |
65 if (type == typeof(Guid)) return new NullableGuidAccessor (typeAccessor, par, expr); | |
66 if (type == typeof(DateTimeOffset)) return new NullableDateTimeOffsetAccessor(typeAccessor, par, expr); | |
67 if (type == typeof(TimeSpan)) return new NullableTimeSpanAccessor (typeAccessor, par, expr); | |
68 break; | |
69 default : break; | |
70 } | |
71 } | |
72 else | |
73 { | |
74 switch (Type.GetTypeCode(underlyingType)) | |
75 { | |
76 case TypeCode.Boolean : return new BooleanAccessor (typeAccessor, par, expr); | |
77 case TypeCode.Char : return new CharAccessor (typeAccessor, par, expr); | |
78 case TypeCode.SByte : return new SByteAccessor (typeAccessor, par, expr); | |
79 case TypeCode.Byte : return new ByteAccessor (typeAccessor, par, expr); | |
80 case TypeCode.Int16 : return new Int16Accessor (typeAccessor, par, expr); | |
81 case TypeCode.UInt16 : return new UInt16Accessor (typeAccessor, par, expr); | |
82 case TypeCode.Int32 : return new Int32Accessor (typeAccessor, par, expr); | |
83 case TypeCode.UInt32 : return new UInt32Accessor (typeAccessor, par, expr); | |
84 case TypeCode.Int64 : return new Int64Accessor (typeAccessor, par, expr); | |
85 case TypeCode.UInt64 : return new UInt64Accessor (typeAccessor, par, expr); | |
86 case TypeCode.Single : return new SingleAccessor (typeAccessor, par, expr); | |
87 case TypeCode.Double : return new DoubleAccessor (typeAccessor, par, expr); | |
88 case TypeCode.Decimal : return new DecimalAccessor (typeAccessor, par, expr); | |
89 case TypeCode.DateTime : return new DateTimeAccessor(typeAccessor, par, expr); | |
90 case TypeCode.Object : | |
91 if (type == typeof(Guid)) return new GuidAccessor (typeAccessor, par, expr); | |
92 if (type == typeof(DateTimeOffset)) return new DateTimeOffsetAccessor(typeAccessor, par, expr); | |
93 if (type == typeof(TimeSpan)) return new TimeSpanAccessor (typeAccessor, par, expr); | |
94 break; | |
95 default : break; | |
96 } | |
97 } | |
98 | |
99 #if !SILVERLIGHT | |
100 | |
101 if (type == typeof(SqlByte)) return new SqlByteAccessor (typeAccessor, par, expr); | |
102 if (type == typeof(SqlInt16)) return new SqlInt16Accessor (typeAccessor, par, expr); | |
103 if (type == typeof(SqlInt32)) return new SqlInt32Accessor (typeAccessor, par, expr); | |
104 if (type == typeof(SqlInt64)) return new SqlInt64Accessor (typeAccessor, par, expr); | |
105 if (type == typeof(SqlSingle)) return new SqlSingleAccessor (typeAccessor, par, expr); | |
106 if (type == typeof(SqlBoolean)) return new SqlBooleanAccessor (typeAccessor, par, expr); | |
107 if (type == typeof(SqlDouble)) return new SqlDoubleAccessor (typeAccessor, par, expr); | |
108 if (type == typeof(SqlDateTime)) return new SqlDateTimeAccessor(typeAccessor, par, expr); | |
109 if (type == typeof(SqlDecimal)) return new SqlDecimalAccessor (typeAccessor, par, expr); | |
110 if (type == typeof(SqlMoney)) return new SqlMoneyAccessor (typeAccessor, par, expr); | |
111 if (type == typeof(SqlString)) return new SqlStringAccessor (typeAccessor, par, expr); | |
112 if (type == typeof(SqlGuid)) return new SqlGuidAccessor (typeAccessor, par, expr); | |
113 | |
114 #endif | |
115 | |
116 return (MemberAccessor)Activator.CreateInstance( | |
117 typeof(BaseAccessor<>).MakeGenericType(type), | |
118 new object[] { typeAccessor, par, expr }); | |
119 } | |
120 | |
121 class BaseAccessor<T> : ExprMemberAccessor | |
122 { | |
123 protected readonly Func <object,T> Getter; | |
124 protected readonly Action<object,T> Setter; | |
125 | |
126 static int _counter; | |
127 | |
128 public BaseAccessor(TypeAccessor typeAccessor, ParameterExpression par, MemberExpression expr) | |
129 : base(typeAccessor, expr.Member) | |
130 { | |
131 Expression ex = expr; | |
132 | |
133 if (TypeHelper.IsEnumOrNullableEnum(ex.Type) && ex.Type != typeof(T)) | |
134 ex = Expression.Convert(ex, typeof(T)); | |
135 | |
136 Getter = Expression.Lambda<Func<object,T>>(ex, par).Compile(); | |
137 | |
138 var mi = expr.Member; | |
139 | |
140 HasSetterValue = !(mi is PropertyInfo) || ((PropertyInfo)mi).GetSetMethod(true) != null; | |
141 | |
142 if (HasSetterValue) | |
143 { | |
144 var dm = new DynamicMethod( | |
145 "setter_" + mi.Name + "_" + ++_counter, | |
146 typeof(void), | |
147 new[] { typeof(object), typeof(T) }, | |
148 typeAccessor.Type); | |
149 var emit = new EmitHelper(dm.GetILGenerator()); | |
150 | |
151 emit | |
152 .ldarg_0 | |
153 .castType (typeAccessor.Type) | |
154 .ldarg_1 | |
155 .end(); | |
156 | |
157 if (mi is FieldInfo) emit.stfld ((FieldInfo)mi); | |
158 else emit.callvirt(((PropertyInfo)mi).GetSetMethod(true)); | |
159 | |
160 emit.ret(); | |
161 | |
162 Setter = (Action<object,T>)dm.CreateDelegate(typeof(Action<object,T>)); | |
163 } | |
164 else | |
165 { | |
166 Setter = (_,__) => {}; | |
167 } | |
168 } | |
169 | |
170 public override object GetValue(object obj) | |
171 { | |
172 return Getter(obj); | |
173 } | |
174 | |
175 public override void SetValue(object obj, object value) | |
176 { | |
177 Setter(obj, ConvertTo<T>.From(value)); | |
178 } | |
179 } | |
180 | |
181 class NullableAccessor<T> : BaseAccessor<T?> | |
182 where T : struct | |
183 { | |
184 public NullableAccessor(TypeAccessor typeAccessor, ParameterExpression par, MemberExpression member) | |
185 : base(typeAccessor, par, member) | |
186 { | |
187 } | |
188 | |
189 public override bool IsNull(object obj) | |
190 { | |
191 return Getter(obj) == null; | |
192 } | |
193 } | |
194 | |
195 #region Basic Types | |
196 | |
197 class BooleanAccessor : BaseAccessor<Boolean> | |
198 { | |
199 public BooleanAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
200 : base(accessor, expression, expr) | |
201 { | |
202 } | |
203 | |
204 public override Boolean GetBoolean(object obj) { return Getter(obj); } | |
205 public override void SetBoolean(object obj, Boolean value) { Setter(obj, value); } | |
206 } | |
207 | |
208 class CharAccessor : BaseAccessor<Char> | |
209 { | |
210 public CharAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
211 : base(accessor, expression, expr) | |
212 { | |
213 } | |
214 | |
215 public override Char GetChar(object obj) { return Getter(obj); } | |
216 public override void SetChar(object obj, Char value) { Setter(obj, value); } | |
217 } | |
218 | |
219 class SByteAccessor : BaseAccessor<SByte> | |
220 { | |
221 public SByteAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
222 : base(accessor, expression, expr) | |
223 { | |
224 } | |
225 | |
226 public override SByte GetSByte(object obj) { return Getter(obj); } | |
227 public override void SetSByte(object obj, SByte value) { Setter(obj, value); } | |
228 } | |
229 | |
230 class ByteAccessor : BaseAccessor<Byte> | |
231 { | |
232 public ByteAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
233 : base(accessor, expression, expr) | |
234 { | |
235 } | |
236 | |
237 public override Byte GetByte(object obj) { return Getter(obj); } | |
238 public override void SetByte(object obj, Byte value) { Setter(obj, value); } | |
239 } | |
240 | |
241 class Int16Accessor : BaseAccessor<Int16> | |
242 { | |
243 public Int16Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
244 : base(accessor, expression, expr) | |
245 { | |
246 } | |
247 | |
248 public override Int16 GetInt16(object obj) { return Getter(obj); } | |
249 public override void SetInt16(object obj, Int16 value) { Setter(obj, value); } | |
250 } | |
251 | |
252 class UInt16Accessor : BaseAccessor<UInt16> | |
253 { | |
254 public UInt16Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
255 : base(accessor, expression, expr) | |
256 { | |
257 } | |
258 | |
259 public override UInt16 GetUInt16(object obj) { return Getter(obj); } | |
260 public override void SetUInt16(object obj, UInt16 value) { Setter(obj, value); } | |
261 } | |
262 | |
263 class Int32Accessor : BaseAccessor<Int32> | |
264 { | |
265 public Int32Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
266 : base(accessor, expression, expr) | |
267 { | |
268 } | |
269 | |
270 public override Int32 GetInt32(object obj) { return Getter(obj); } | |
271 public override void SetInt32(object obj, Int32 value) { Setter(obj, value); } | |
272 } | |
273 | |
274 class UInt32Accessor : BaseAccessor<UInt32> | |
275 { | |
276 public UInt32Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
277 : base(accessor, expression, expr) | |
278 { | |
279 } | |
280 | |
281 public override UInt32 GetUInt32(object obj) { return Getter(obj); } | |
282 public override void SetUInt32(object obj, UInt32 value) { Setter(obj, value); } | |
283 } | |
284 | |
285 class Int64Accessor : BaseAccessor<Int64> | |
286 { | |
287 public Int64Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
288 : base(accessor, expression, expr) | |
289 { | |
290 } | |
291 | |
292 public override Int64 GetInt64(object obj) { return Getter(obj); } | |
293 public override void SetInt64(object obj, Int64 value) { Setter(obj, value); } | |
294 } | |
295 | |
296 class UInt64Accessor : BaseAccessor<UInt64> | |
297 { | |
298 public UInt64Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
299 : base(accessor, expression, expr) | |
300 { | |
301 } | |
302 | |
303 public override UInt64 GetUInt64(object obj) { return Getter(obj); } | |
304 public override void SetUInt64(object obj, UInt64 value) { Setter(obj, value); } | |
305 } | |
306 | |
307 class SingleAccessor : BaseAccessor<Single> | |
308 { | |
309 public SingleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
310 : base(accessor, expression, expr) | |
311 { | |
312 } | |
313 | |
314 public override Single GetSingle(object obj) { return Getter(obj); } | |
315 public override void SetSingle(object obj, Single value) { Setter(obj, value); } | |
316 } | |
317 | |
318 class DoubleAccessor : BaseAccessor<Double> | |
319 { | |
320 public DoubleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
321 : base(accessor, expression, expr) | |
322 { | |
323 } | |
324 | |
325 public override Double GetDouble(object obj) { return Getter(obj); } | |
326 public override void SetDouble(object obj, Double value) { Setter(obj, value); } | |
327 } | |
328 | |
329 class DecimalAccessor : BaseAccessor<Decimal> | |
330 { | |
331 public DecimalAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
332 : base(accessor, expression, expr) | |
333 { | |
334 } | |
335 | |
336 public override Decimal GetDecimal(object obj) { return Getter(obj); } | |
337 public override void SetDecimal(object obj, Decimal value) { Setter(obj, value); } | |
338 } | |
339 | |
340 class DateTimeAccessor : BaseAccessor<DateTime> | |
341 { | |
342 public DateTimeAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
343 : base(accessor, expression, expr) | |
344 { | |
345 } | |
346 | |
347 public override DateTime GetDateTime(object obj) { return Getter(obj); } | |
348 public override void SetDateTime(object obj, DateTime value) { Setter(obj, value); } | |
349 } | |
350 | |
351 class GuidAccessor : BaseAccessor<Guid> | |
352 { | |
353 public GuidAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
354 : base(accessor, expression, expr) | |
355 { | |
356 } | |
357 | |
358 public override Guid GetGuid(object obj) { return Getter(obj); } | |
359 public override void SetGuid(object obj, Guid value) { Setter(obj, value); } | |
360 } | |
361 | |
362 class DateTimeOffsetAccessor : BaseAccessor<DateTimeOffset> | |
363 { | |
364 public DateTimeOffsetAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
365 : base(accessor, expression, expr) | |
366 { | |
367 } | |
368 | |
369 public override DateTimeOffset GetDateTimeOffset(object obj) { return Getter(obj); } | |
370 public override void SetDateTimeOffset(object obj, DateTimeOffset value) { Setter(obj, value); } | |
371 } | |
372 | |
373 class TimeSpanAccessor : BaseAccessor<TimeSpan> | |
374 { | |
375 public TimeSpanAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
376 : base(accessor, expression, expr) | |
377 { | |
378 } | |
379 | |
380 public override TimeSpan GetTimeSpan(object obj) { return Getter(obj); } | |
381 public override void SetTimeSpan(object obj, TimeSpan value) { Setter(obj, value); } | |
382 } | |
383 | |
384 #endregion | |
385 | |
386 #region Nullable | |
387 | |
388 class NullableBooleanAccessor : NullableAccessor<Boolean> | |
389 { | |
390 public NullableBooleanAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
391 : base(accessor, expression, expr) | |
392 { | |
393 } | |
394 | |
395 public override Boolean? GetNullableBoolean(object obj) { return Getter(obj); } | |
396 public override void SetNullableBoolean(object obj, Boolean? value) { Setter(obj, value); } | |
397 } | |
398 | |
399 class NullableCharAccessor : NullableAccessor<Char> | |
400 { | |
401 public NullableCharAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
402 : base(accessor, expression, expr) | |
403 { | |
404 } | |
405 | |
406 public override Char? GetNullableChar(object obj) { return Getter(obj); } | |
407 public override void SetNullableChar(object obj, Char? value) { Setter(obj, value); } | |
408 } | |
409 | |
410 class NullableSByteAccessor : NullableAccessor<SByte> | |
411 { | |
412 public NullableSByteAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
413 : base(accessor, expression, expr) | |
414 { | |
415 } | |
416 | |
417 public override SByte? GetNullableSByte(object obj) { return Getter(obj); } | |
418 public override void SetNullableSByte(object obj, SByte? value) { Setter(obj, value); } | |
419 } | |
420 | |
421 class NullableByteAccessor : NullableAccessor<Byte> | |
422 { | |
423 public NullableByteAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
424 : base(accessor, expression, expr) | |
425 { | |
426 } | |
427 | |
428 public override Byte? GetNullableByte(object obj) { return Getter(obj); } | |
429 public override void SetNullableByte(object obj, Byte? value) { Setter(obj, value); } | |
430 } | |
431 | |
432 class NullableInt16Accessor : NullableAccessor<Int16> | |
433 { | |
434 public NullableInt16Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
435 : base(accessor, expression, expr) | |
436 { | |
437 } | |
438 | |
439 public override Int16? GetNullableInt16(object obj) { return Getter(obj); } | |
440 public override void SetNullableInt16(object obj, Int16? value) { Setter(obj, value); } | |
441 } | |
442 | |
443 class NullableUInt16Accessor : NullableAccessor<UInt16> | |
444 { | |
445 public NullableUInt16Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
446 : base(accessor, expression, expr) | |
447 { | |
448 } | |
449 | |
450 public override UInt16? GetNullableUInt16(object obj) { return Getter(obj); } | |
451 public override void SetNullableUInt16(object obj, UInt16? value) { Setter(obj, value); } | |
452 } | |
453 | |
454 class NullableInt32Accessor : NullableAccessor<Int32> | |
455 { | |
456 public NullableInt32Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
457 : base(accessor, expression, expr) | |
458 { | |
459 } | |
460 | |
461 public override Int32? GetNullableInt32(object obj) { return Getter(obj); } | |
462 public override void SetNullableInt32(object obj, Int32? value) { Setter(obj, value); } | |
463 } | |
464 | |
465 class NullableUInt32Accessor : NullableAccessor<UInt32> | |
466 { | |
467 public NullableUInt32Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
468 : base(accessor, expression, expr) | |
469 { | |
470 } | |
471 | |
472 public override UInt32? GetNullableUInt32(object obj) { return Getter(obj); } | |
473 public override void SetNullableUInt32(object obj, UInt32? value) { Setter(obj, value); } | |
474 } | |
475 | |
476 class NullableInt64Accessor : NullableAccessor<Int64> | |
477 { | |
478 public NullableInt64Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
479 : base(accessor, expression, expr) | |
480 { | |
481 } | |
482 | |
483 public override Int64? GetNullableInt64(object obj) { return Getter(obj); } | |
484 public override void SetNullableInt64(object obj, Int64? value) { Setter(obj, value); } | |
485 } | |
486 | |
487 class NullableUInt64Accessor : NullableAccessor<UInt64> | |
488 { | |
489 public NullableUInt64Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
490 : base(accessor, expression, expr) | |
491 { | |
492 } | |
493 | |
494 public override UInt64? GetNullableUInt64(object obj) { return Getter(obj); } | |
495 public override void SetNullableUInt64(object obj, UInt64? value) { Setter(obj, value); } | |
496 } | |
497 | |
498 class NullableSingleAccessor : NullableAccessor<Single> | |
499 { | |
500 public NullableSingleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
501 : base(accessor, expression, expr) | |
502 { | |
503 } | |
504 | |
505 public override Single? GetNullableSingle(object obj) { return Getter(obj); } | |
506 public override void SetNullableSingle(object obj, Single? value) { Setter(obj, value); } | |
507 } | |
508 | |
509 class NullableDoubleAccessor : NullableAccessor<Double> | |
510 { | |
511 public NullableDoubleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
512 : base(accessor, expression, expr) | |
513 { | |
514 } | |
515 | |
516 public override Double? GetNullableDouble(object obj) { return Getter(obj); } | |
517 public override void SetNullableDouble(object obj, Double? value) { Setter(obj, value); } | |
518 } | |
519 | |
520 class NullableDecimalAccessor : NullableAccessor<Decimal> | |
521 { | |
522 public NullableDecimalAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
523 : base(accessor, expression, expr) | |
524 { | |
525 } | |
526 | |
527 public override Decimal? GetNullableDecimal(object obj) { return Getter(obj); } | |
528 public override void SetNullableDecimal(object obj, Decimal? value) { Setter(obj, value); } | |
529 } | |
530 | |
531 class NullableDateTimeAccessor : NullableAccessor<DateTime> | |
532 { | |
533 public NullableDateTimeAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
534 : base(accessor, expression, expr) | |
535 { | |
536 } | |
537 | |
538 public override DateTime? GetNullableDateTime(object obj) { return Getter(obj); } | |
539 public override void SetNullableDateTime(object obj, DateTime? value) { Setter(obj, value); } | |
540 } | |
541 | |
542 class NullableGuidAccessor : NullableAccessor<Guid> | |
543 { | |
544 public NullableGuidAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
545 : base(accessor, expression, expr) | |
546 { | |
547 } | |
548 | |
549 public override Guid? GetNullableGuid(object obj) { return Getter(obj); } | |
550 public override void SetNullableGuid(object obj, Guid? value) { Setter(obj, value); } | |
551 } | |
552 | |
553 class NullableDateTimeOffsetAccessor : NullableAccessor<DateTimeOffset> | |
554 { | |
555 public NullableDateTimeOffsetAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
556 : base(accessor, expression, expr) | |
557 { | |
558 } | |
559 | |
560 public override DateTimeOffset? GetNullableDateTimeOffset(object obj) { return Getter(obj); } | |
561 public override void SetNullableDateTimeOffset(object obj, DateTimeOffset? value) { Setter(obj, value); } | |
562 } | |
563 | |
564 class NullableTimeSpanAccessor : NullableAccessor<TimeSpan> | |
565 { | |
566 public NullableTimeSpanAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
567 : base(accessor, expression, expr) | |
568 { | |
569 } | |
570 | |
571 public override TimeSpan? GetNullableTimeSpan(object obj) { return Getter(obj); } | |
572 public override void SetNullableTimeSpan(object obj, TimeSpan? value) { Setter(obj, value); } | |
573 } | |
574 | |
575 #endregion | |
576 | |
577 #region Sql Types | |
578 | |
579 #if !SILVERLIGHT | |
580 | |
581 class SqlByteAccessor : BaseAccessor<SqlByte> | |
582 { | |
583 public SqlByteAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
584 : base(accessor, expression, expr) | |
585 { | |
586 } | |
587 | |
588 public override SqlByte GetSqlByte(object obj) { return Getter(obj); } | |
589 public override void SetSqlByte(object obj, SqlByte value) { Setter(obj, value); } | |
590 } | |
591 | |
592 class SqlInt16Accessor : BaseAccessor<SqlInt16> | |
593 { | |
594 public SqlInt16Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
595 : base(accessor, expression, expr) | |
596 { | |
597 } | |
598 | |
599 public override SqlInt16 GetSqlInt16(object obj) { return Getter(obj); } | |
600 public override void SetSqlInt16(object obj, SqlInt16 value) { Setter(obj, value); } | |
601 } | |
602 | |
603 class SqlInt32Accessor : BaseAccessor<SqlInt32> | |
604 { | |
605 public SqlInt32Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
606 : base(accessor, expression, expr) | |
607 { | |
608 } | |
609 | |
610 public override SqlInt32 GetSqlInt32(object obj) { return Getter(obj); } | |
611 public override void SetSqlInt32(object obj, SqlInt32 value) { Setter(obj, value); } | |
612 } | |
613 | |
614 class SqlInt64Accessor : BaseAccessor<SqlInt64> | |
615 { | |
616 public SqlInt64Accessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
617 : base(accessor, expression, expr) | |
618 { | |
619 } | |
620 | |
621 public override SqlInt64 GetSqlInt64(object obj) { return Getter(obj); } | |
622 public override void SetSqlInt64(object obj, SqlInt64 value) { Setter(obj, value); } | |
623 } | |
624 | |
625 class SqlSingleAccessor : BaseAccessor<SqlSingle> | |
626 { | |
627 public SqlSingleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
628 : base(accessor, expression, expr) | |
629 { | |
630 } | |
631 | |
632 public override SqlSingle GetSqlSingle(object obj) { return Getter(obj); } | |
633 public override void SetSqlSingle(object obj, SqlSingle value) { Setter(obj, value); } | |
634 } | |
635 | |
636 class SqlBooleanAccessor : BaseAccessor<SqlBoolean> | |
637 { | |
638 public SqlBooleanAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
639 : base(accessor, expression, expr) | |
640 { | |
641 } | |
642 | |
643 public override SqlBoolean GetSqlBoolean(object obj) { return Getter(obj); } | |
644 public override void SetSqlBoolean(object obj, SqlBoolean value) { Setter(obj, value); } | |
645 } | |
646 | |
647 class SqlDoubleAccessor : BaseAccessor<SqlDouble> | |
648 { | |
649 public SqlDoubleAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
650 : base(accessor, expression, expr) | |
651 { | |
652 } | |
653 | |
654 public override SqlDouble GetSqlDouble(object obj) { return Getter(obj); } | |
655 public override void SetSqlDouble(object obj, SqlDouble value) { Setter(obj, value); } | |
656 } | |
657 | |
658 class SqlDateTimeAccessor : BaseAccessor<SqlDateTime> | |
659 { | |
660 public SqlDateTimeAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
661 : base(accessor, expression, expr) | |
662 { | |
663 } | |
664 | |
665 public override SqlDateTime GetSqlDateTime(object obj) { return Getter(obj); } | |
666 public override void SetSqlDateTime(object obj, SqlDateTime value) { Setter(obj, value); } | |
667 } | |
668 | |
669 class SqlDecimalAccessor : BaseAccessor<SqlDecimal> | |
670 { | |
671 public SqlDecimalAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
672 : base(accessor, expression, expr) | |
673 { | |
674 } | |
675 | |
676 public override SqlDecimal GetSqlDecimal(object obj) { return Getter(obj); } | |
677 public override void SetSqlDecimal(object obj, SqlDecimal value) { Setter(obj, value); } | |
678 } | |
679 | |
680 class SqlMoneyAccessor : BaseAccessor<SqlMoney> | |
681 { | |
682 public SqlMoneyAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
683 : base(accessor, expression, expr) | |
684 { | |
685 } | |
686 | |
687 public override SqlMoney GetSqlMoney(object obj) { return Getter(obj); } | |
688 public override void SetSqlMoney(object obj, SqlMoney value) { Setter(obj, value); } | |
689 } | |
690 | |
691 class SqlStringAccessor : BaseAccessor<SqlString> | |
692 { | |
693 public SqlStringAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
694 : base(accessor, expression, expr) | |
695 { | |
696 } | |
697 | |
698 public override SqlString GetSqlString(object obj) { return Getter(obj); } | |
699 public override void SetSqlString(object obj, SqlString value) { Setter(obj, value); } | |
700 } | |
701 | |
702 class SqlGuidAccessor : BaseAccessor<SqlGuid> | |
703 { | |
704 public SqlGuidAccessor(TypeAccessor accessor, ParameterExpression expression, MemberExpression expr) | |
705 : base(accessor, expression, expr) | |
706 { | |
707 } | |
708 | |
709 public override SqlGuid GetSqlGuid(object obj) { return Getter(obj); } | |
710 public override void SetSqlGuid(object obj, SqlGuid value) { Setter(obj, value); } | |
711 } | |
712 | |
713 #endif | |
714 | |
715 #endregion | |
716 } | |
717 } |