Skip to content

Commit 4669ce6

Browse files
committed
Release 3.8.1: Fixed issue #65
1 parent 6425cf5 commit 4669ce6

4 files changed

Lines changed: 244 additions & 12 deletions

File tree

src/Patterns/Mapping/IMappingServices.cs

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,138 @@
2323

2424
#endregion
2525

26+
using System;
27+
2628
using AutoMapper;
2729

2830
namespace Patterns.Mapping
2931
{
3032
/// <summary>
31-
/// Aggregates central AutoMapper services.
33+
/// Aggregates central AutoMapper services.
3234
/// </summary>
3335
public interface IMappingServices
3436
{
3537
/// <summary>
36-
/// Gets the engine.
38+
/// Gets the engine.
3739
/// </summary>
3840
/// <value>
39-
/// The engine.
41+
/// The engine.
4042
/// </value>
4143
IMappingEngine Engine { get; }
4244

4345
/// <summary>
44-
/// Gets the configuration.
46+
/// Gets the configuration.
4547
/// </summary>
4648
/// <value>
47-
/// The configuration.
49+
/// The configuration.
4850
/// </value>
4951
IConfiguration Configuration { get; }
5052

5153
/// <summary>
52-
/// Gets the configuration provider.
54+
/// Gets the configuration provider.
5355
/// </summary>
5456
/// <value>
55-
/// The configuration provider.
57+
/// The configuration provider.
5658
/// </value>
5759
IConfigurationProvider ConfigurationProvider { get; }
5860

5961
/// <summary>
60-
/// Maps the specified source to the indicated destination.
62+
/// Maps the specified source to the indicated destination.
6163
/// </summary>
6264
/// <typeparam name="TSource">The type of the source.</typeparam>
6365
/// <typeparam name="TDestination">The type of the destination.</typeparam>
6466
/// <param name="source">The source.</param>
6567
/// <returns></returns>
6668
TDestination Map<TSource, TDestination>(TSource source);
69+
70+
/// <summary>
71+
/// Maps the specified source to the indicated destination.
72+
/// </summary>
73+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
74+
/// <param name="source">The source.</param>
75+
/// <returns></returns>
76+
TDestination Map<TDestination>(object source);
77+
78+
/// <summary>
79+
/// Maps the specified source to the indicated destination.
80+
/// </summary>
81+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
82+
/// <param name="source">The source.</param>
83+
/// <param name="opts">The opts.</param>
84+
/// <returns></returns>
85+
TDestination Map<TDestination>(object source, Action<IMappingOperationOptions> opts);
86+
87+
/// <summary>
88+
/// Maps the specified source to the indicated destination.
89+
/// </summary>
90+
/// <typeparam name="TSource">The type of the source.</typeparam>
91+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
92+
/// <param name="source">The source.</param>
93+
/// <param name="opts">The opts.</param>
94+
/// <returns></returns>
95+
TDestination Map<TSource, TDestination>(TSource source, Action<IMappingOperationOptions> opts);
96+
97+
/// <summary>
98+
/// Maps the specified source to the specified destination.
99+
/// </summary>
100+
/// <typeparam name="TSource">The type of the source.</typeparam>
101+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
102+
/// <param name="source">The source.</param>
103+
/// <param name="destination">The destination.</param>
104+
/// <returns></returns>
105+
TDestination Map<TSource, TDestination>(TSource source, TDestination destination);
106+
107+
/// <summary>
108+
/// Maps the specified source to the specified destination.
109+
/// </summary>
110+
/// <typeparam name="TSource">The type of the source.</typeparam>
111+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
112+
/// <param name="source">The source.</param>
113+
/// <param name="destination">The destination.</param>
114+
/// <param name="opts">The opts.</param>
115+
/// <returns></returns>
116+
TDestination Map<TSource, TDestination>(TSource source, TDestination destination,
117+
Action<IMappingOperationOptions> opts);
118+
119+
/// <summary>
120+
/// Maps the specified source to the indicated destination.
121+
/// </summary>
122+
/// <param name="source">The source.</param>
123+
/// <param name="sourceType">Type of the source.</param>
124+
/// <param name="destinationType">Type of the destination.</param>
125+
/// <returns></returns>
126+
object Map(object source, Type sourceType, Type destinationType);
127+
128+
/// <summary>
129+
/// Maps the specified source to the indicated destination.
130+
/// </summary>
131+
/// <param name="source">The source.</param>
132+
/// <param name="sourceType">Type of the source.</param>
133+
/// <param name="destinationType">Type of the destination.</param>
134+
/// <param name="opts">The opts.</param>
135+
/// <returns></returns>
136+
object Map(object source, Type sourceType, Type destinationType, Action<IMappingOperationOptions> opts);
137+
138+
/// <summary>
139+
/// Maps the specified source to the specified destination.
140+
/// </summary>
141+
/// <param name="source">The source.</param>
142+
/// <param name="destination">The destination.</param>
143+
/// <param name="sourceType">Type of the source.</param>
144+
/// <param name="destinationType">Type of the destination.</param>
145+
/// <returns></returns>
146+
object Map(object source, object destination, Type sourceType, Type destinationType);
147+
148+
/// <summary>
149+
/// Maps the specified source to the specified destination.
150+
/// </summary>
151+
/// <param name="source">The source.</param>
152+
/// <param name="destination">The destination.</param>
153+
/// <param name="sourceType">Type of the source.</param>
154+
/// <param name="destinationType">Type of the destination.</param>
155+
/// <param name="opts">The opts.</param>
156+
/// <returns></returns>
157+
object Map(object source, object destination, Type sourceType, Type destinationType,
158+
Action<IMappingOperationOptions> opts);
67159
}
68160
}

src/Patterns/Mapping/MappingServices.cs

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#endregion
2525

26+
using System;
27+
2628
using AutoMapper;
2729

2830
namespace Patterns.Mapping
@@ -93,10 +95,148 @@ public IConfigurationProvider ConfigurationProvider
9395
/// <exception cref="System.NotImplementedException"></exception>
9496
public TDestination Map<TSource, TDestination>(TSource source)
9597
{
96-
if (ConfigurationProvider.FindTypeMapFor(typeof (TSource), typeof (TDestination)) == null)
97-
Configuration.CreateMap<TSource, TDestination>();
98+
EnsureTypeMapPresence(typeof (TSource), typeof (TDestination));
9899

99100
return Engine.Map<TSource, TDestination>(source);
100101
}
102+
103+
/// <summary>
104+
/// Maps the specified source to the indicated destination.
105+
/// </summary>
106+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
107+
/// <param name="source">The source.</param>
108+
/// <returns></returns>
109+
public TDestination Map<TDestination>(object source)
110+
{
111+
EnsureTypeMapPresence(source.GetType(), typeof (TDestination));
112+
113+
return Engine.Map<TDestination>(source);
114+
}
115+
116+
/// <summary>
117+
/// Maps the specified source to the indicated destination.
118+
/// </summary>
119+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
120+
/// <param name="source">The source.</param>
121+
/// <param name="opts">The opts.</param>
122+
/// <returns></returns>
123+
public TDestination Map<TDestination>(object source, Action<IMappingOperationOptions> opts)
124+
{
125+
EnsureTypeMapPresence(source.GetType(), typeof (TDestination));
126+
127+
return Engine.Map<TDestination>(source, opts);
128+
}
129+
130+
/// <summary>
131+
/// Maps the specified source to the indicated destination.
132+
/// </summary>
133+
/// <typeparam name="TSource">The type of the source.</typeparam>
134+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
135+
/// <param name="source">The source.</param>
136+
/// <param name="opts">The opts.</param>
137+
/// <returns></returns>
138+
public TDestination Map<TSource, TDestination>(TSource source, Action<IMappingOperationOptions> opts)
139+
{
140+
EnsureTypeMapPresence(typeof (TSource), typeof (TDestination));
141+
142+
return Engine.Map<TSource, TDestination>(source, opts);
143+
}
144+
145+
/// <summary>
146+
/// Maps the specified source to the specified destination.
147+
/// </summary>
148+
/// <typeparam name="TSource">The type of the source.</typeparam>
149+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
150+
/// <param name="source">The source.</param>
151+
/// <param name="destination">The destination.</param>
152+
/// <returns></returns>
153+
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
154+
{
155+
EnsureTypeMapPresence(typeof (TSource), typeof (TDestination));
156+
157+
return Engine.Map(source, destination);
158+
}
159+
160+
/// <summary>
161+
/// Maps the specified source to the specified destination.
162+
/// </summary>
163+
/// <typeparam name="TSource">The type of the source.</typeparam>
164+
/// <typeparam name="TDestination">The type of the destination.</typeparam>
165+
/// <param name="source">The source.</param>
166+
/// <param name="destination">The destination.</param>
167+
/// <param name="opts">The opts.</param>
168+
/// <returns></returns>
169+
public TDestination Map<TSource, TDestination>(TSource source, TDestination destination, Action<IMappingOperationOptions> opts)
170+
{
171+
EnsureTypeMapPresence(typeof(TSource), typeof(TDestination));
172+
173+
return Engine.Map(source, destination, opts);
174+
}
175+
176+
/// <summary>
177+
/// Maps the specified source to the indicated destination.
178+
/// </summary>
179+
/// <param name="source">The source.</param>
180+
/// <param name="sourceType">Type of the source.</param>
181+
/// <param name="destinationType">Type of the destination.</param>
182+
/// <returns></returns>
183+
public object Map(object source, Type sourceType, Type destinationType)
184+
{
185+
EnsureTypeMapPresence(sourceType, destinationType);
186+
187+
return Engine.Map(source, sourceType, destinationType);
188+
}
189+
190+
/// <summary>
191+
/// Maps the specified source to the indicated destination.
192+
/// </summary>
193+
/// <param name="source">The source.</param>
194+
/// <param name="sourceType">Type of the source.</param>
195+
/// <param name="destinationType">Type of the destination.</param>
196+
/// <param name="opts">The opts.</param>
197+
/// <returns></returns>
198+
public object Map(object source, Type sourceType, Type destinationType, Action<IMappingOperationOptions> opts)
199+
{
200+
EnsureTypeMapPresence(sourceType, destinationType);
201+
202+
return Engine.Map(source, sourceType, destinationType, opts);
203+
}
204+
205+
/// <summary>
206+
/// Maps the specified source to the specified destination.
207+
/// </summary>
208+
/// <param name="source">The source.</param>
209+
/// <param name="destination">The destination.</param>
210+
/// <param name="sourceType">Type of the source.</param>
211+
/// <param name="destinationType">Type of the destination.</param>
212+
/// <returns></returns>
213+
public object Map(object source, object destination, Type sourceType, Type destinationType)
214+
{
215+
EnsureTypeMapPresence(sourceType, destinationType);
216+
217+
return Engine.Map(source, destination, sourceType, destinationType);
218+
}
219+
220+
/// <summary>
221+
/// Maps the specified source to the specified destination.
222+
/// </summary>
223+
/// <param name="source">The source.</param>
224+
/// <param name="destination">The destination.</param>
225+
/// <param name="sourceType">Type of the source.</param>
226+
/// <param name="destinationType">Type of the destination.</param>
227+
/// <param name="opts">The opts.</param>
228+
/// <returns></returns>
229+
public object Map(object source, object destination, Type sourceType, Type destinationType, Action<IMappingOperationOptions> opts)
230+
{
231+
EnsureTypeMapPresence(sourceType, destinationType);
232+
233+
return Engine.Map(source, destination, sourceType, destinationType, opts);
234+
}
235+
236+
private void EnsureTypeMapPresence(Type sourceType, Type destinationType)
237+
{
238+
if (ConfigurationProvider.FindTypeMapFor(sourceType, destinationType) == null)
239+
Configuration.CreateMap(sourceType, destinationType);
240+
}
101241
}
102242
}

src/Patterns/SolutionAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
[assembly: AssemblyCulture("")]
3232
[assembly: ComVisible(false)]
3333
[assembly: NeutralResourcesLanguage("en-US")]
34-
[assembly: AssemblyVersion("3.8.0")]
34+
[assembly: AssemblyVersion("3.8.1")]

src/Patterns/SolutionAssemblyInfo.settings.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Settings.Initialize(
33
majorNumber: 3,
44
minorNumber: 8,
5-
patchNumber: 0,
5+
patchNumber: 1,
66
buildNumber: null,
77
buildLevel: BuildLevels.None
88
);

0 commit comments

Comments
 (0)