Mercurial > pub > bltoolkit
comparison Source/Mapping/EnumeratorMapper.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.Collections; | |
3 | |
4 using BLToolkit.Reflection; | |
5 | |
6 namespace BLToolkit.Mapping | |
7 { | |
8 public class EnumeratorMapper : IMapDataSourceList | |
9 { | |
10 public EnumeratorMapper(IEnumerator enumerator) | |
11 { | |
12 _enumerator = enumerator; | |
13 } | |
14 | |
15 private readonly IEnumerator _enumerator; | |
16 private Type _objectType; | |
17 | |
18 #region IMapDataSourceList Members | |
19 | |
20 public virtual void InitMapping(InitContext initContext) | |
21 { | |
22 _enumerator.Reset(); | |
23 } | |
24 | |
25 public virtual bool SetNextDataSource(InitContext initContext) | |
26 { | |
27 if (initContext == null) throw new ArgumentNullException("initContext"); | |
28 | |
29 if (_enumerator.MoveNext() == false) | |
30 return false; | |
31 | |
32 object sourceObject = _enumerator.Current; | |
33 | |
34 if (_objectType != sourceObject.GetType()) | |
35 { | |
36 _objectType = sourceObject.GetType(); | |
37 initContext.DataSource = initContext.MappingSchema.GetObjectMapper(_objectType); | |
38 } | |
39 | |
40 initContext.SourceObject = sourceObject; | |
41 | |
42 return true; | |
43 } | |
44 | |
45 public virtual void EndMapping(InitContext initContext) | |
46 { | |
47 } | |
48 | |
49 #endregion | |
50 } | |
51 } |