2323
2424#endregion
2525
26+ using System ;
27+
2628using AutoMapper ;
2729
2830namespace 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}
0 commit comments