Mercurial > pub > bltoolkit
comparison Source/Mapping/ObjectListMapper.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.Collections; | |
2 | |
3 using BLToolkit.Reflection; | |
4 | |
5 namespace BLToolkit.Mapping | |
6 { | |
7 public class ObjectListMapper : IMapDataSourceList, IMapDataDestinationList | |
8 { | |
9 public ObjectListMapper(IList list, ObjectMapper objectMapper) | |
10 { | |
11 _list = list; | |
12 _mapper = objectMapper; | |
13 } | |
14 | |
15 private readonly IList _list; | |
16 private ObjectMapper _mapper; | |
17 private int _currentItem; | |
18 | |
19 #region IMapDataSourceList Members | |
20 | |
21 void IMapDataSourceList.InitMapping(InitContext initContext) | |
22 { | |
23 initContext.DataSource = _mapper; | |
24 } | |
25 | |
26 bool IMapDataSourceList.SetNextDataSource(InitContext initContext) | |
27 { | |
28 if (_currentItem >= _list.Count) | |
29 return false; | |
30 | |
31 initContext.SourceObject = _list[_currentItem]; | |
32 _currentItem++; | |
33 | |
34 return true; | |
35 } | |
36 | |
37 void IMapDataSourceList.EndMapping(InitContext initContext) | |
38 { | |
39 } | |
40 | |
41 #endregion | |
42 | |
43 #region IMapDataDestinationList Members | |
44 | |
45 void IMapDataDestinationList.InitMapping(InitContext initContext) | |
46 { | |
47 ISupportMapping sm = _list as ISupportMapping; | |
48 | |
49 if (sm != null) | |
50 { | |
51 sm.BeginMapping(initContext); | |
52 | |
53 if (initContext.ObjectMapper != null && _mapper != initContext.ObjectMapper) | |
54 _mapper = initContext.ObjectMapper; | |
55 } | |
56 } | |
57 | |
58 IMapDataDestination IMapDataDestinationList.GetDataDestination(InitContext initContext) | |
59 { | |
60 return _mapper; | |
61 } | |
62 | |
63 private object _currentObject; | |
64 | |
65 private void AddCurrent() | |
66 { | |
67 if (_currentObject != null) | |
68 { | |
69 _list.Add(_currentObject); | |
70 _currentObject = null; | |
71 } | |
72 } | |
73 | |
74 object IMapDataDestinationList.GetNextObject(InitContext initContext) | |
75 { | |
76 AddCurrent(); | |
77 | |
78 return _currentObject = _mapper.CreateInstance(initContext); | |
79 } | |
80 | |
81 void IMapDataDestinationList.EndMapping(InitContext initContext) | |
82 { | |
83 AddCurrent(); | |
84 | |
85 ISupportMapping sm = _list as ISupportMapping; | |
86 | |
87 if (sm != null) | |
88 sm.EndMapping(initContext); | |
89 } | |
90 | |
91 #endregion | |
92 } | |
93 } |