diff options
* Renamed a bunch of Data baseclasses for clarity and readability
(Slowly getting there)
Diffstat (limited to 'ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs')
-rw-r--r-- | ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs new file mode 100644 index 0000000..2ab8daf --- /dev/null +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs | |||
@@ -0,0 +1,85 @@ | |||
1 | /* | ||
2 | * Copyright (c) Tribal Media AB, http://tribalmedia.se/ | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions are met: | ||
6 | * * Redistributions of source code must retain the above copyright | ||
7 | * notice, this list of conditions and the following disclaimer. | ||
8 | * * Redistributions in binary form must reproduce the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer in the | ||
10 | * documentation and/or other materials provided with the distribution. | ||
11 | * * The name of Tribal Media AB may not be used to endorse or promote products | ||
12 | * derived from this software without specific prior written permission. | ||
13 | * | ||
14 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
17 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
23 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | using TribalMedia.Framework.Data; | ||
28 | |||
29 | namespace TribalMedia.Framework.Data | ||
30 | { | ||
31 | public abstract class RowMapper | ||
32 | { | ||
33 | public abstract void FillObject(DataReader reader); | ||
34 | } | ||
35 | |||
36 | public class ObjectMapper<TObj> : RowMapper | ||
37 | { | ||
38 | private readonly Schema m_schema; | ||
39 | private readonly TObj m_obj; | ||
40 | |||
41 | public TObj Object | ||
42 | { | ||
43 | get { return m_obj; } | ||
44 | } | ||
45 | |||
46 | public ObjectMapper(Schema schema, TObj obj) | ||
47 | { | ||
48 | m_schema = schema; | ||
49 | m_obj = obj; | ||
50 | } | ||
51 | |||
52 | public override void FillObject(DataReader reader) | ||
53 | { | ||
54 | foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values) | ||
55 | { | ||
56 | fieldMapper.SetPropertyFromReader(m_obj, reader); | ||
57 | } | ||
58 | } | ||
59 | } | ||
60 | |||
61 | public class RowMapper<TObj> : RowMapper | ||
62 | { | ||
63 | private readonly Schema m_schema; | ||
64 | private readonly TObj m_obj; | ||
65 | |||
66 | public TObj Object | ||
67 | { | ||
68 | get { return m_obj; } | ||
69 | } | ||
70 | |||
71 | public RowMapper(Schema schema, TObj obj) | ||
72 | { | ||
73 | m_schema = schema; | ||
74 | m_obj = obj; | ||
75 | } | ||
76 | |||
77 | public override void FillObject(DataReader reader) | ||
78 | { | ||
79 | foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values) | ||
80 | { | ||
81 | fieldMapper.SetPropertyFromReader(this, reader); | ||
82 | } | ||
83 | } | ||
84 | } | ||
85 | } \ No newline at end of file | ||