-
Notifications
You must be signed in to change notification settings - Fork 685
/
Copy pathAutoMap.cs
143 lines (128 loc) · 5.66 KB
/
AutoMap.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#if USE_NULLABLE
#nullable enable
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace FluentNHibernate.Automapping;
/// <summary>
/// Starting point for automapping your entities.
/// </summary>
public static class AutoMap
{
/// <summary>
/// Automatically map classes in the assembly that contains <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">Class in the assembly you want to map</typeparam>
public static AutoPersistenceModel AssemblyOf<T>()
{
return Assembly(typeof(T).Assembly);
}
/// <summary>
/// Automatically map classes in the assembly that contains <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">Class in the assembly you want to map</typeparam>
/// <param name="cfg">Automapping configuration</param>
public static AutoPersistenceModel AssemblyOf<T>(IAutomappingConfiguration cfg)
{
return Assembly(typeof(T).Assembly, cfg);
}
/// <summary>
/// Automatically map the classes in <paramref name="assembly"/>.
/// </summary>
/// <param name="assembly">Assembly containing the classes to map</param>
public static AutoPersistenceModel Assembly(Assembly assembly)
{
return Source(new AssemblyTypeSource(assembly));
}
/// <summary>
/// Automatically map the classes in <paramref name="assembly"/>.
/// </summary>
/// <param name="assembly">Assembly containing the classes to map</param>
/// <param name="cfg">Automapping configuration</param>
public static AutoPersistenceModel Assembly(Assembly assembly, IAutomappingConfiguration cfg)
{
return Source(new AssemblyTypeSource(assembly), cfg);
}
/// <summary>
/// Automatically map the classes in each assembly supplied.
/// </summary>
/// <param name="assemblies">Assemblies containing classes to map</param>
public static AutoPersistenceModel Assemblies(params Assembly[] assemblies)
{
return Source(new CombinedAssemblyTypeSource(assemblies.Select(x => new AssemblyTypeSource(x))));
}
/// <summary>
/// Automatically map the classes in each assembly supplied.
/// </summary>
/// <param name="cfg">Automapping configuration</param>
/// <param name="assemblies">Assemblies containing classes to map</param>
public static AutoPersistenceModel Assemblies(IAutomappingConfiguration cfg, params Assembly[] assemblies)
{
return Source(new CombinedAssemblyTypeSource(assemblies.Select(x => new AssemblyTypeSource(x))), cfg);
}
/// <summary>
/// Automatically map the classes in each assembly supplied.
/// </summary>
/// <param name="cfg">Automapping configuration</param>
/// <param name="assemblies">Assemblies containing classes to map</param>
public static AutoPersistenceModel Assemblies(IAutomappingConfiguration cfg, IEnumerable<Assembly> assemblies)
{
return Source(new CombinedAssemblyTypeSource(assemblies.Select(x => new AssemblyTypeSource(x))), cfg);
}
/// <summary>
/// Automatically map the classes exposed through the supplied <see cref="ITypeSource"/>.
/// </summary>
/// <param name="source"><see cref="ITypeSource"/> containing classes to map</param>
public static AutoPersistenceModel Source(ITypeSource source)
{
return new AutoPersistenceModel()
.AddTypeSource(source);
}
/// <summary>
/// Automatically map the classes exposed through the supplied <see cref="ITypeSource"/>.
/// </summary>
/// <param name="source"><see cref="ITypeSource"/> containing classes to map</param>
/// <param name="cfg">Automapping configuration</param>
public static AutoPersistenceModel Source(ITypeSource source, IAutomappingConfiguration cfg)
{
return new AutoPersistenceModel(cfg)
.AddTypeSource(source);
}
#region Depreciated overloads
/// <summary>
/// Automatically map the classes exposed through the supplied <see cref="ITypeSource"/>.
/// </summary>
/// <param name="source"><see cref="ITypeSource"/> containing classes to map</param>
/// <param name="where">Criteria for selecting a subset of the types in the assembly for mapping</param>
[Obsolete("Depreciated overload. Use either chained Where method or ShouldMap(Type) in IAutomappingConfiguration.")]
public static AutoPersistenceModel Source(ITypeSource source, Func<Type, bool> where)
{
return Source(source)
.Where(where);
}
/// <summary>
/// Automatically map the classes in <paramref name="assembly"/>.
/// </summary>
/// <param name="assembly">Assembly containing the classes to map</param>
/// <param name="where">Criteria for selecting a subset of the types in the assembly for mapping</param>
[Obsolete("Depreciated overload. Use either chained Where method or ShouldMap(Type) in IAutomappingConfiguration.")]
public static AutoPersistenceModel Assembly(Assembly assembly, Func<Type, bool> where)
{
return Source(new AssemblyTypeSource(assembly))
.Where(where);
}
/// <summary>
/// Automatically map classes in the assembly that contains <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">Class in the assembly you want to map</typeparam>
/// <param name="where">Criteria for selecting a subset of the types in the assembly for mapping</param>
[Obsolete("Depreciated overload. Use either chained Where method or ShouldMap(Type) in IAutomappingConfiguration.")]
public static AutoPersistenceModel AssemblyOf<T>(Func<Type, bool> where)
{
return Assembly(typeof(T).Assembly)
.Where(where);
}
#endregion
}