Mercurial > pub > bltoolkit
comparison Source/Mapping/DataTableMapper.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.Data; | |
| 2 | |
| 3 using BLToolkit.Reflection; | |
| 4 | |
| 5 namespace BLToolkit.Mapping | |
| 6 { | |
| 7 public class DataTableMapper : IMapDataSourceList, IMapDataDestinationList | |
| 8 { | |
| 9 public DataTableMapper(DataTable dataTable, DataRowMapper mapper) | |
| 10 { | |
| 11 _table = dataTable; | |
| 12 _mapper = mapper; | |
| 13 } | |
| 14 | |
| 15 private readonly DataTable _table; | |
| 16 private readonly DataRowMapper _mapper; | |
| 17 private int _currentRow; | |
| 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 (_currentRow >= _table.Rows.Count) | |
| 29 return false; | |
| 30 | |
| 31 DataRow row = _table.Rows[_currentRow++]; | |
| 32 | |
| 33 if (row.RowState == DataRowState.Deleted) | |
| 34 return ((IMapDataSourceList)this).SetNextDataSource(initContext); | |
| 35 | |
| 36 _mapper.DataRow = row; | |
| 37 initContext.SourceObject = row; | |
| 38 | |
| 39 return true; | |
| 40 } | |
| 41 | |
| 42 void IMapDataSourceList.EndMapping(InitContext initContext) | |
| 43 { | |
| 44 } | |
| 45 | |
| 46 #endregion | |
| 47 | |
| 48 #region IMapDataDestinationList Members | |
| 49 | |
| 50 void IMapDataDestinationList.InitMapping(InitContext initContext) | |
| 51 { | |
| 52 } | |
| 53 | |
| 54 IMapDataDestination IMapDataDestinationList.GetDataDestination(InitContext initContext) | |
| 55 { | |
| 56 return _mapper; | |
| 57 } | |
| 58 | |
| 59 object IMapDataDestinationList.GetNextObject(InitContext initContext) | |
| 60 { | |
| 61 DataRow row = _table.NewRow(); | |
| 62 | |
| 63 _mapper.DataRow = row; | |
| 64 _table.Rows.Add(row); | |
| 65 | |
| 66 return row; | |
| 67 } | |
| 68 | |
| 69 void IMapDataDestinationList.EndMapping(InitContext initContext) | |
| 70 { | |
| 71 } | |
| 72 | |
| 73 #endregion | |
| 74 } | |
| 75 } | 
