Skip to content

Commit 7831112

Browse files
committed
- v11.0.1
1 parent 37b32f4 commit 7831112

3 files changed

Lines changed: 144 additions & 139 deletions

File tree

Shuttle.Core.Data/DataRowMapper.cs

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,84 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Data;
4-
using System.Linq;
5-
using Shuttle.Core.Contract;
6-
7-
namespace Shuttle.Core.Data
8-
{
9-
public class DataRowMapper : IDataRowMapper
10-
{
11-
public MappedRow<T> MapRow<T>(DataRow row) where T : new()
12-
{
13-
Guard.AgainstNull(row, nameof(row));
14-
15-
return new MappedRow<T>(row, Map<T>(row));
16-
}
17-
18-
public IEnumerable<MappedRow<T>> MapRows<T>(IEnumerable<DataRow> rows) where T : new()
19-
{
20-
return rows?.Select(row => new MappedRow<T>(row, Map<T>(row))).ToList() ?? new List<MappedRow<T>>();
21-
}
22-
23-
public T MapObject<T>(DataRow row) where T : new()
24-
{
25-
return Map<T>(row);
26-
}
27-
28-
public IEnumerable<T> MapObjects<T>(IEnumerable<DataRow> rows) where T : new()
29-
{
30-
return rows?.Select(Map<T>).ToList() ?? new List<T>();
31-
}
32-
33-
public T MapValue<T>(DataRow row)
34-
{
35-
return MapRowValue<T>(row);
36-
}
37-
38-
public IEnumerable<T> MapValues<T>(IEnumerable<DataRow> rows)
39-
{
40-
return rows?.Select(MapRowValue<T>).ToList() ?? new List<T>();
41-
}
42-
43-
private T Map<T>(DataRow row) where T : new()
44-
{
45-
var result = new T();
46-
var type = typeof(T);
47-
48-
foreach (var pi in type.GetProperties())
49-
{
50-
try
51-
{
52-
var value = row.Table.Columns.Contains(pi.Name) ? row[pi.Name] : null;
53-
54-
if (value == null)
55-
{
56-
continue;
57-
}
58-
59-
pi.SetValue(result, value, null);
60-
}
61-
catch
62-
{
63-
// ignored
64-
}
65-
}
66-
67-
return result;
68-
}
69-
70-
private static T MapRowValue<T>(DataRow row)
71-
{
72-
var underlyingSystemType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
73-
74-
return row?[0] == null
75-
? default(T)
76-
: (T)Convert.ChangeType(row[0], underlyingSystemType);
77-
}
78-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using Shuttle.Core.Contract;
6+
7+
namespace Shuttle.Core.Data
8+
{
9+
public class DataRowMapper : IDataRowMapper
10+
{
11+
public MappedRow<T> MapRow<T>(DataRow row) where T : new()
12+
{
13+
Guard.AgainstNull(row, nameof(row));
14+
15+
return new MappedRow<T>(row, Map<T>(row));
16+
}
17+
18+
public IEnumerable<MappedRow<T>> MapRows<T>(IEnumerable<DataRow> rows) where T : new()
19+
{
20+
return rows?.Select(row => new MappedRow<T>(row, Map<T>(row))).ToList() ?? new List<MappedRow<T>>();
21+
}
22+
23+
public T MapObject<T>(DataRow row) where T : new()
24+
{
25+
return Map<T>(row);
26+
}
27+
28+
public IEnumerable<T> MapObjects<T>(IEnumerable<DataRow> rows) where T : new()
29+
{
30+
return rows?.Select(Map<T>).ToList() ?? new List<T>();
31+
}
32+
33+
public T MapValue<T>(DataRow row)
34+
{
35+
return MapRowValue<T>(row);
36+
}
37+
38+
public IEnumerable<T> MapValues<T>(IEnumerable<DataRow> rows)
39+
{
40+
return rows?.Select(MapRowValue<T>).ToList() ?? new List<T>();
41+
}
42+
43+
private T Map<T>(DataRow row) where T : new()
44+
{
45+
if (row == null)
46+
{
47+
return default(T);
48+
}
49+
50+
var result = new T();
51+
var type = typeof(T);
52+
53+
foreach (var pi in type.GetProperties())
54+
{
55+
try
56+
{
57+
var value = row.Table.Columns.Contains(pi.Name) ? row[pi.Name] : null;
58+
59+
if (value == null)
60+
{
61+
continue;
62+
}
63+
64+
pi.SetValue(result, value, null);
65+
}
66+
catch
67+
{
68+
// ignored
69+
}
70+
}
71+
72+
return result;
73+
}
74+
75+
private static T MapRowValue<T>(DataRow row)
76+
{
77+
var underlyingSystemType = Nullable.GetUnderlyingType(typeof(T)) ?? typeof(T);
78+
79+
return row?[0] == null
80+
? default(T)
81+
: (T)Convert.ChangeType(row[0], underlyingSystemType);
82+
}
83+
}
7984
}
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
using System.Collections.Generic;
2-
using System.Data;
3-
4-
namespace Shuttle.Core.Data
5-
{
6-
public interface IDataRowMapper
7-
{
8-
MappedRow<T> MapRow<T>(DataRow row) where T : new();
9-
IEnumerable<MappedRow<T>> MapRows<T>(IEnumerable<DataRow> rows) where T : new();
10-
T MapObject<T>(DataRow row) where T : new();
11-
IEnumerable<T> MapObjects<T>(IEnumerable<DataRow> rows) where T : new();
12-
T MapValue<T>(DataRow row);
13-
IEnumerable<T> MapValues<T>(IEnumerable<DataRow> rows);
14-
}
15-
16-
public interface IDataRowMapper<T> where T : class
17-
{
18-
MappedRow<T> Map(DataRow row);
19-
}
1+
using System.Collections.Generic;
2+
using System.Data;
3+
4+
namespace Shuttle.Core.Data
5+
{
6+
public interface IDataRowMapper
7+
{
8+
MappedRow<T> MapRow<T>(DataRow row) where T : new();
9+
IEnumerable<MappedRow<T>> MapRows<T>(IEnumerable<DataRow> rows) where T : new();
10+
T MapObject<T>(DataRow row) where T : new();
11+
IEnumerable<T> MapObjects<T>(IEnumerable<DataRow> rows) where T : new();
12+
T MapValue<T>(DataRow row);
13+
IEnumerable<T> MapValues<T>(IEnumerable<DataRow> rows);
14+
}
15+
16+
public interface IDataRowMapper<T> where T : class
17+
{
18+
MappedRow<T> Map(DataRow row);
19+
}
2020
}
Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
using System.Reflection;
2-
using System.Runtime.InteropServices;
3-
4-
#if NET46
5-
[assembly: AssemblyTitle(".NET Framework 4.6")]
6-
#endif
7-
8-
#if NET461
9-
[assembly: AssemblyTitle(".NET Framework 4.6.1")]
10-
#endif
11-
12-
#if NET462
13-
[assembly: AssemblyTitle(".NET Framework 4.6.2")]
14-
#endif
15-
16-
#if NET47
17-
[assembly: AssemblyTitle(".NET Framework 4.7")]
18-
#endif
19-
20-
#if NET471
21-
[assembly: AssemblyTitle(".NET Framework 4.7.1")]
22-
#endif
23-
24-
#if NETCOREAPP2_0
25-
[assembly: AssemblyTitle(".NET Core 2.0")]
26-
#endif
27-
28-
#if NETCOREAPP2_1
29-
[assembly: AssemblyTitle(".NET Core 2.1")]
30-
#endif
31-
32-
#if NETSTANDARD2_0
33-
[assembly: AssemblyTitle(".NET Standard 2.0")]
34-
#endif
35-
36-
[assembly: AssemblyVersion("11.0.0.0")]
37-
[assembly: AssemblyCopyright("Copyright © Eben Roux 2017")]
38-
[assembly: AssemblyProduct("Shuttle.Core.Data")]
39-
[assembly: AssemblyCompany("Shuttle")]
40-
[assembly: AssemblyConfiguration("Release")]
41-
[assembly: AssemblyInformationalVersion("11.0.0")]
42-
[assembly: ComVisible(false)]
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
#if NET46
5+
[assembly: AssemblyTitle(".NET Framework 4.6")]
6+
#endif
7+
8+
#if NET461
9+
[assembly: AssemblyTitle(".NET Framework 4.6.1")]
10+
#endif
11+
12+
#if NET462
13+
[assembly: AssemblyTitle(".NET Framework 4.6.2")]
14+
#endif
15+
16+
#if NET47
17+
[assembly: AssemblyTitle(".NET Framework 4.7")]
18+
#endif
19+
20+
#if NET471
21+
[assembly: AssemblyTitle(".NET Framework 4.7.1")]
22+
#endif
23+
24+
#if NETCOREAPP2_0
25+
[assembly: AssemblyTitle(".NET Core 2.0")]
26+
#endif
27+
28+
#if NETCOREAPP2_1
29+
[assembly: AssemblyTitle(".NET Core 2.1")]
30+
#endif
31+
32+
#if NETSTANDARD2_0
33+
[assembly: AssemblyTitle(".NET Standard 2.0")]
34+
#endif
35+
36+
[assembly: AssemblyVersion("11.0.1.0")]
37+
[assembly: AssemblyCopyright("Copyright © Eben Roux 2019")]
38+
[assembly: AssemblyProduct("Shuttle.Core.Data")]
39+
[assembly: AssemblyCompany("Shuttle")]
40+
[assembly: AssemblyConfiguration("Release")]
41+
[assembly: AssemblyInformationalVersion("11.0.1")]
42+
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)