This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 88
/
Convention.cs
98 lines (87 loc) · 3.28 KB
/
Convention.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Dapper.FluentMap.Mapping;
namespace Dapper.FluentMap.Conventions
{
/// <summary>
/// Represents a convention for mapping entity properties to column names.
/// </summary>
public abstract class Convention
{
/// <summary>
/// Initializes a new instance of the <see cref="T:Dapper.FluentMap.Conventions.Convention"/> class.
/// </summary>
protected Convention()
{
ConventionConfigurations = new List<PropertyConventionConfiguration>();
PropertyMaps = new List<PropertyMap>();
}
/// <summary>
/// Gets the convention configurations for the properties.
/// </summary>
public IList<PropertyConventionConfiguration> ConventionConfigurations { get; }
/// <summary>
/// Gets the property mappings.
/// </summary>
public IList<PropertyMap> PropertyMaps { get; }
/// <summary>
/// Configures a convention that applies on all properties of the entity.
/// </summary>
/// <returns>A configuration object for the convention.</returns>
protected PropertyConventionConfiguration Properties()
{
var config = new PropertyConventionConfiguration();
ConventionConfigurations.Add(config);
return config;
}
/// <summary>
/// Configures a convention that applies on all the properties of a specified type of the entity.
/// </summary>
/// <typeparam name="T">The type of the properties that the convention will apply to.</typeparam>
/// <returns>A configuration object for the convention.</returns>
protected PropertyConventionConfiguration Properties<T>()
{
var type = typeof(T);
PropertyConventionConfiguration config;
if (Nullable.GetUnderlyingType(type) != null)
{
// Convention defined for nullable type, match nullable properties
config = new PropertyConventionConfiguration().Where(p => p.PropertyType == type);
}
else
{
// Convention defined for non-nullable types, match both nullabel and non-nullable properties
config = new PropertyConventionConfiguration().Where(p => (Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType) == type);
}
ConventionConfigurations.Add(config);
return config;
}
#region EditorBrowsableStates
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override string ToString()
{
return base.ToString();
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override bool Equals(object obj)
{
return base.Equals(obj);
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <inheritdoc/>
[EditorBrowsable(EditorBrowsableState.Never)]
public new Type GetType()
{
return base.GetType();
}
#endregion
}
}