Mercurial > pub > bltoolkit
comparison Source/Mapping/ScalarDataReaderMapper.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; | |
3 | |
4 using BLToolkit.Common; | |
5 using System.Data.SqlTypes; | |
6 | |
7 namespace BLToolkit.Mapping | |
8 { | |
9 public class ScalarDataReaderMapper : DataReaderMapper | |
10 { | |
11 public ScalarDataReaderMapper( | |
12 MappingSchema mappingSchema, | |
13 IDataReader dataReader, | |
14 NameOrIndexParameter nameOrIndex) | |
15 : base(mappingSchema, dataReader) | |
16 { | |
17 _index = nameOrIndex.ByName? dataReader.GetOrdinal(nameOrIndex.Name): nameOrIndex.Index; | |
18 } | |
19 | |
20 private readonly int _index; | |
21 public int Index | |
22 { | |
23 get { return _index; } | |
24 } | |
25 | |
26 #region IMapDataSource Members | |
27 | |
28 public override int Count | |
29 { | |
30 get { return 1; } | |
31 } | |
32 | |
33 public override Type GetFieldType(int index) | |
34 { | |
35 return DataReader.GetFieldType(_index); | |
36 } | |
37 | |
38 public override string GetName(int index) | |
39 { | |
40 return DataReader.GetName(_index); | |
41 } | |
42 | |
43 public override object GetValue(object o, int index) | |
44 { | |
45 return base.GetValue(o, _index); | |
46 } | |
47 | |
48 public override object GetValue(object o, string name) | |
49 { | |
50 return base.GetValue(o, _index); | |
51 } | |
52 | |
53 public override bool IsNull (object o, int index) { return DataReader.IsDBNull(_index); } | |
54 | |
55 // Simple type getters. | |
56 // | |
57 [CLSCompliant(false)] | |
58 public override SByte GetSByte (object o, int index) { return base.GetSByte(o, _index); } | |
59 public override Int16 GetInt16 (object o, int index) { return DataReader.GetInt16 (_index); } | |
60 public override Int32 GetInt32 (object o, int index) { return DataReader.GetInt32 (_index); } | |
61 public override Int64 GetInt64 (object o, int index) { return DataReader.GetInt64 (_index); } | |
62 | |
63 public override Byte GetByte (object o, int index) { return DataReader.GetByte (_index); } | |
64 [CLSCompliant(false)] | |
65 public override UInt16 GetUInt16 (object o, int index) { return base.GetUInt16(o, _index); } | |
66 [CLSCompliant(false)] | |
67 public override UInt32 GetUInt32 (object o, int index) { return base.GetUInt32(o, _index); } | |
68 [CLSCompliant(false)] | |
69 public override UInt64 GetUInt64 (object o, int index) { return base.GetUInt64(o, _index); } | |
70 | |
71 public override Boolean GetBoolean (object o, int index) { return DataReader.GetBoolean (_index); } | |
72 public override Char GetChar (object o, int index) { return DataReader.GetChar (_index); } | |
73 public override Single GetSingle (object o, int index) { return DataReader.GetFloat (_index); } | |
74 public override Double GetDouble (object o, int index) { return DataReader.GetDouble (_index); } | |
75 public override Decimal GetDecimal (object o, int index) { return DataReader.GetDecimal (_index); } | |
76 public override Guid GetGuid (object o, int index) { return DataReader.GetGuid (_index); } | |
77 public override DateTime GetDateTime(object o, int index) { return DataReader.GetDateTime(_index); } | |
78 public override DateTimeOffset GetDateTimeOffset(object o, int index) { return (DateTimeOffset)DataReader.GetValue(_index); } | |
79 | |
80 // Nullable type getters. | |
81 // | |
82 [CLSCompliant(false)] | |
83 public override SByte? GetNullableSByte (object o, int index) { return base.GetNullableSByte(o, _index); } | |
84 public override Int16? GetNullableInt16 (object o, int index) { return DataReader.IsDBNull(_index)? null: (Int16?)DataReader.GetInt16 (_index); } | |
85 public override Int32? GetNullableInt32 (object o, int index) { return DataReader.IsDBNull(_index)? null: (Int32?)DataReader.GetInt32 (_index); } | |
86 public override Int64? GetNullableInt64 (object o, int index) { return DataReader.IsDBNull(_index)? null: (Int64?)DataReader.GetInt64 (_index); } | |
87 | |
88 public override Byte? GetNullableByte (object o, int index) { return DataReader.IsDBNull(_index)? null: (Byte?) DataReader.GetByte (_index); } | |
89 [CLSCompliant(false)] | |
90 public override UInt16? GetNullableUInt16 (object o, int index) { return base.GetNullableUInt16(o, _index); } | |
91 [CLSCompliant(false)] | |
92 public override UInt32? GetNullableUInt32 (object o, int index) { return base.GetNullableUInt32(o, _index); } | |
93 [CLSCompliant(false)] | |
94 public override UInt64? GetNullableUInt64 (object o, int index) { return base.GetNullableUInt64(o, _index); } | |
95 | |
96 public override Boolean? GetNullableBoolean (object o, int index) { return DataReader.IsDBNull(_index)? null: (Boolean?) DataReader.GetBoolean (_index); } | |
97 public override Char? GetNullableChar (object o, int index) { return DataReader.IsDBNull(_index)? null: (Char?) DataReader.GetChar (_index); } | |
98 public override Single? GetNullableSingle (object o, int index) { return DataReader.IsDBNull(_index)? null: (Single?) DataReader.GetFloat (_index); } | |
99 public override Double? GetNullableDouble (object o, int index) { return DataReader.IsDBNull(_index)? null: (Double?) DataReader.GetDouble (_index); } | |
100 public override Decimal? GetNullableDecimal (object o, int index) { return DataReader.IsDBNull(_index)? null: (Decimal?) DataReader.GetDecimal (_index); } | |
101 public override Guid? GetNullableGuid (object o, int index) { return DataReader.IsDBNull(_index)? null: (Guid?) DataReader.GetGuid (_index); } | |
102 public override DateTime? GetNullableDateTime(object o, int index) { return DataReader.IsDBNull(_index)? null: (DateTime?)DataReader.GetDateTime(_index); } | |
103 public override DateTimeOffset? GetNullableDateTimeOffset(object o, int index) { return DataReader.IsDBNull(_index)? null: (DateTimeOffset?)DataReader.GetValue(_index); } | |
104 | |
105 #if !SILVERLIGHT | |
106 | |
107 // SQL type getters. | |
108 // | |
109 public override SqlByte GetSqlByte (object o, int index) { return DataReader.IsDBNull(_index)? SqlByte. Null: DataReader.GetByte (_index); } | |
110 public override SqlInt16 GetSqlInt16 (object o, int index) { return DataReader.IsDBNull(_index)? SqlInt16. Null: DataReader.GetInt16 (_index); } | |
111 public override SqlInt32 GetSqlInt32 (object o, int index) { return DataReader.IsDBNull(_index)? SqlInt32. Null: DataReader.GetInt32 (_index); } | |
112 public override SqlInt64 GetSqlInt64 (object o, int index) { return DataReader.IsDBNull(_index)? SqlInt64. Null: DataReader.GetInt64 (_index); } | |
113 public override SqlSingle GetSqlSingle (object o, int index) { return DataReader.IsDBNull(_index)? SqlSingle. Null: DataReader.GetFloat (_index); } | |
114 public override SqlBoolean GetSqlBoolean (object o, int index) { return DataReader.IsDBNull(_index)? SqlBoolean. Null: DataReader.GetBoolean (_index); } | |
115 public override SqlDouble GetSqlDouble (object o, int index) { return DataReader.IsDBNull(_index)? SqlDouble. Null: DataReader.GetDouble (_index); } | |
116 public override SqlDateTime GetSqlDateTime(object o, int index) { return DataReader.IsDBNull(_index)? SqlDateTime.Null: DataReader.GetDateTime(_index); } | |
117 public override SqlDecimal GetSqlDecimal (object o, int index) { return DataReader.IsDBNull(_index)? SqlDecimal. Null: DataReader.GetDecimal (_index); } | |
118 public override SqlMoney GetSqlMoney (object o, int index) { return DataReader.IsDBNull(_index)? SqlMoney. Null: DataReader.GetDecimal (_index); } | |
119 public override SqlGuid GetSqlGuid (object o, int index) { return DataReader.IsDBNull(_index)? SqlGuid. Null: DataReader.GetGuid (_index); } | |
120 public override SqlString GetSqlString (object o, int index) { return DataReader.IsDBNull(_index)? SqlString. Null: DataReader.GetString (_index); } | |
121 | |
122 #endif | |
123 | |
124 #endregion | |
125 } | |
126 } |