Mercurial > pub > bltoolkit
view Source/Mapping/DataTableMapper.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System.Data; using BLToolkit.Reflection; namespace BLToolkit.Mapping { public class DataTableMapper : IMapDataSourceList, IMapDataDestinationList { public DataTableMapper(DataTable dataTable, DataRowMapper mapper) { _table = dataTable; _mapper = mapper; } private readonly DataTable _table; private readonly DataRowMapper _mapper; private int _currentRow; #region IMapDataSourceList Members void IMapDataSourceList.InitMapping(InitContext initContext) { initContext.DataSource = _mapper; } bool IMapDataSourceList.SetNextDataSource(InitContext initContext) { if (_currentRow >= _table.Rows.Count) return false; DataRow row = _table.Rows[_currentRow++]; if (row.RowState == DataRowState.Deleted) return ((IMapDataSourceList)this).SetNextDataSource(initContext); _mapper.DataRow = row; initContext.SourceObject = row; return true; } void IMapDataSourceList.EndMapping(InitContext initContext) { } #endregion #region IMapDataDestinationList Members void IMapDataDestinationList.InitMapping(InitContext initContext) { } IMapDataDestination IMapDataDestinationList.GetDataDestination(InitContext initContext) { return _mapper; } object IMapDataDestinationList.GetNextObject(InitContext initContext) { DataRow row = _table.NewRow(); _mapper.DataRow = row; _table.Rows.Add(row); return row; } void IMapDataDestinationList.EndMapping(InitContext initContext) { } #endregion } }