@@ -8,7 +8,6 @@ namespace AgileObjects.AgileMapper.ObjectPopulation
88 using Enumerables ;
99 using Extensions . Internal ;
1010 using Queryables ;
11- using Validation ;
1211
1312 internal class ObjectMapperFactory
1413 {
@@ -45,77 +44,16 @@ public void RegisterCreationCallback(MapperCreationCallbackKey creationCallbackK
4544
4645 public ObjectMapper < TSource , TTarget > GetOrCreateRoot < TSource , TTarget > ( ObjectMappingData < TSource , TTarget > mappingData )
4746 {
48- if ( TryGetStaticallyCachedMapper ( mappingData , out var mapper ) )
47+ if ( StaticMapperCache < TSource , TTarget > . TryGetMapperFor ( mappingData , out var mapper ) )
4948 {
5049 return mapper ;
5150 }
5251
53- // TODO: This is not thread-safe when using a fixed-types RootObjectMapperKey!
5452 mappingData . MapperKey . MappingData = mappingData ;
5553
5654 mapper = ( ObjectMapper < TSource , TTarget > ) _rootMappersCache . GetOrAdd (
5755 mappingData . MapperKey ,
58- key =>
59- {
60- var mapperToCache = key . MappingData . GetOrCreateMapper ( ) ;
61- var data = key . MappingData ;
62-
63- key . MappingData = null ;
64-
65- if ( mapperToCache . MapperData . MapperContext . UserConfigurations . ValidateMappingPlans )
66- {
67- MappingValidator . Validate ( mapperToCache . MapperData ) ;
68- }
69-
70- if ( mapperToCache . IsStaticallyCacheable ( key ) )
71- {
72- var ruleSets = data . MapperData . MapperContext . RuleSets ;
73-
74- if ( data . MappingContext . RuleSet == ruleSets . CreateNew )
75- {
76- if ( StaticCreateNewMapperCache < TSource , TTarget > . Mapper != null )
77- {
78- goto SkipStaticCaching ;
79- }
80-
81- return StaticCreateNewMapperCache < TSource , TTarget > . SetMapper ( ( ObjectMapper < TSource , TTarget > ) mapperToCache ) ;
82- }
83-
84- if ( data . MappingContext . RuleSet == ruleSets . Overwrite )
85- {
86- if ( StaticOverwriteMapperCache < TSource , TTarget > . Mapper != null )
87- {
88- goto SkipStaticCaching ;
89- }
90-
91- return StaticOverwriteMapperCache < TSource , TTarget > . SetMapper ( ( ObjectMapper < TSource , TTarget > ) mapperToCache ) ;
92- }
93-
94- if ( data . MappingContext . RuleSet == ruleSets . Project )
95- {
96- if ( StaticProjectionMapperCache < TSource , TTarget > . Mapper != null )
97- {
98- goto SkipStaticCaching ;
99- }
100-
101- return StaticProjectionMapperCache < TSource , TTarget > . SetMapper ( ( ObjectMapper < TSource , TTarget > ) mapperToCache ) ;
102- }
103-
104- if ( data . MappingContext . RuleSet == ruleSets . Merge )
105- {
106- if ( StaticMergeMapperCache < TSource , TTarget > . Mapper != null )
107- {
108- goto SkipStaticCaching ;
109- }
110-
111- return StaticMergeMapperCache < TSource , TTarget > . SetMapper ( ( ObjectMapper < TSource , TTarget > ) mapperToCache ) ;
112- }
113- }
114-
115- SkipStaticCaching :
116-
117- return mapperToCache ;
118- } ) ;
56+ key => key . MappingData . GetOrCreateMapper ( ) ) ;
11957
12058 return mapper ;
12159 }
@@ -154,107 +92,6 @@ public ObjectMapper<TSource, TTarget> Create<TSource, TTarget>(ObjectMappingData
15492 return mapper ;
15593 }
15694
157- #region Static Caches
158-
159- private static bool TryGetStaticallyCachedMapper < TSource , TTarget > (
160- ObjectMappingData < TSource , TTarget > mappingData ,
161- out ObjectMapper < TSource , TTarget > mapper )
162- {
163- var ruleSet = mappingData . MappingContext . RuleSet ;
164- var ruleSets = mappingData . MapperContext . RuleSets ;
165-
166- if ( ruleSet == ruleSets . CreateNew )
167- {
168- if ( StaticCreateNewMapperCache < TSource , TTarget > . Mapper ? . MapperData . MapperContext != mappingData . MapperContext )
169- {
170- goto NoCachedMapper ;
171- }
172-
173- mapper = StaticCreateNewMapperCache < TSource , TTarget > . Mapper ;
174- return true ;
175- }
176-
177- if ( ruleSet == ruleSets . Overwrite )
178- {
179- if ( StaticOverwriteMapperCache < TSource , TTarget > . Mapper ? . MapperData . MapperContext != mappingData . MapperContext )
180- {
181- goto NoCachedMapper ;
182- }
183-
184- mapper = StaticOverwriteMapperCache < TSource , TTarget > . Mapper ;
185- return true ;
186- }
187-
188- if ( ruleSet == ruleSets . Project )
189- {
190- if ( StaticProjectionMapperCache < TSource , TTarget > . Mapper ? . MapperData . MapperContext != mappingData . MapperContext )
191- {
192- goto NoCachedMapper ;
193- }
194-
195- mapper = StaticProjectionMapperCache < TSource , TTarget > . Mapper ;
196- return true ;
197- }
198-
199- if ( ruleSet == ruleSets . Merge )
200- {
201- if ( StaticMergeMapperCache < TSource , TTarget > . Mapper ? . MapperData . MapperContext != mappingData . MapperContext )
202- {
203- goto NoCachedMapper ;
204- }
205-
206- mapper = StaticMergeMapperCache < TSource , TTarget > . Mapper ;
207- return true ;
208- }
209-
210- NoCachedMapper :
211-
212- mapper = null ;
213- return false ;
214- }
215-
216- private static class StaticCreateNewMapperCache < TSource , TTarget >
217- {
218- public static ObjectMapper < TSource , TTarget > Mapper { get ; private set ; }
219-
220- public static ObjectMapper < TSource , TTarget > SetMapper ( ObjectMapper < TSource , TTarget > mapper )
221- => Mapper = mapper . WithResetCallback ( Reset ) ;
222-
223- private static void Reset ( ) => Mapper = null ;
224- }
225-
226- private static class StaticOverwriteMapperCache < TSource , TTarget >
227- {
228- public static ObjectMapper < TSource , TTarget > Mapper { get ; private set ; }
229-
230- public static ObjectMapper < TSource , TTarget > SetMapper ( ObjectMapper < TSource , TTarget > mapper )
231- => Mapper = mapper . WithResetCallback ( Reset ) ;
232-
233- private static void Reset ( ) => Mapper = null ;
234- }
235-
236- private static class StaticProjectionMapperCache < TSource , TTarget >
237- {
238- public static ObjectMapper < TSource , TTarget > Mapper { get ; private set ; }
239-
240- public static ObjectMapper < TSource , TTarget > SetMapper ( ObjectMapper < TSource , TTarget > mapper )
241- => Mapper = mapper . WithResetCallback ( Reset ) ;
242-
243- private static void Reset ( ) => Mapper = null ;
244- }
245-
246- private static class StaticMergeMapperCache < TSource , TTarget >
247- {
248- public static ObjectMapper < TSource , TTarget > Mapper { get ; private set ; }
249-
250- public static ObjectMapper < TSource , TTarget > SetMapper ( ObjectMapper < TSource , TTarget > mapper )
251- => Mapper = mapper . WithResetCallback ( Reset ) ;
252-
253- private static void Reset ( ) => Mapper = null ;
254- }
255-
256- #endregion
257-
25895 public void Reset ( )
25996 {
26097 foreach ( var mappingExpressionFactory in _mappingExpressionFactories )
0 commit comments