-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleMemberMap.cs
69 lines (61 loc) · 2.49 KB
/
SimpleMemberMap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Reflection;
namespace Dapper
{
/// <summary>
/// Represents simple member map for one of target parameter or property or field to source DataReader column
/// </summary>
internal sealed class SimpleMemberMap : SqlMapper.IMemberMap
{
/// <summary>
/// Creates instance for simple property mapping
/// </summary>
/// <param name="columnName">DataReader column name</param>
/// <param name="property">Target property</param>
public SimpleMemberMap(string columnName, PropertyInfo property)
{
ColumnName = columnName ?? throw new ArgumentNullException(nameof(columnName));
Property = property ?? throw new ArgumentNullException(nameof(property));
}
/// <summary>
/// Creates instance for simple field mapping
/// </summary>
/// <param name="columnName">DataReader column name</param>
/// <param name="field">Target property</param>
public SimpleMemberMap(string columnName, FieldInfo field)
{
ColumnName = columnName ?? throw new ArgumentNullException(nameof(columnName));
Field = field ?? throw new ArgumentNullException(nameof(field));
}
/// <summary>
/// Creates instance for simple constructor parameter mapping
/// </summary>
/// <param name="columnName">DataReader column name</param>
/// <param name="parameter">Target constructor parameter</param>
public SimpleMemberMap(string columnName, ParameterInfo parameter)
{
ColumnName = columnName ?? throw new ArgumentNullException(nameof(columnName));
Parameter = parameter ?? throw new ArgumentNullException(nameof(parameter));
}
/// <summary>
/// DataReader column name
/// </summary>
public string ColumnName { get; }
/// <summary>
/// Target member type
/// </summary>
public Type MemberType => Field?.FieldType ?? Property?.PropertyType ?? Parameter?.ParameterType;
/// <summary>
/// Target property
/// </summary>
public PropertyInfo Property { get; }
/// <summary>
/// Target field
/// </summary>
public FieldInfo Field { get; }
/// <summary>
/// Target constructor parameter
/// </summary>
public ParameterInfo Parameter { get; }
}
}