mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.0 KiB
36 lines
1.0 KiB
using System;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
|
|
namespace ZeroLevel.SqlServer
|
|
{
|
|
public class DbMapper<T> : DbMapper, IDbMapper<T>
|
|
{
|
|
public DbMapper(bool mapOnlyMarkedMembers) : base(typeof(T), mapOnlyMarkedMembers)
|
|
{
|
|
}
|
|
|
|
public new T Deserialize(DataRow row)
|
|
{
|
|
if (null == row) throw new ArgumentNullException(nameof(row));
|
|
var result = Activator.CreateInstance<T>();
|
|
foreach (var field in _fields)
|
|
{
|
|
field.Value.SetValue(result, row[field.Key], typeConverter);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public new T Deserialize(DbDataReader reader)
|
|
{
|
|
if (null == reader) throw new ArgumentNullException(nameof(reader));
|
|
var result = Activator.CreateInstance<T>();
|
|
foreach (var field in _fields)
|
|
{
|
|
field.Value.SetValue(result, reader[field.Key], typeConverter);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|