1010
1111namespace Mapster
1212{
13- public class TypeAdapterConfig : ITypeAdapterConfig
13+ public class TypeAdapterConfig : ITypeAdapterConfig , IConfigConcurrency
1414 {
1515 [ AdaptIgnore ]
1616 public bool IsGlobalSettings { get ; private set ; }
@@ -29,7 +29,7 @@ public class TypeAdapterConfig : ITypeAdapterConfig
2929 [ AdaptIgnore ]
3030 public ConfigCompileStorage ConfigCompile { get ; private set ; }
3131
32- public bool ConcurencyEnviroment { get ; set ; }
32+ public bool ConcurrencyEnvironment { get ; set ; }
3333
3434 [ AdaptIgnore ]
3535 public AutoResetEvent Configure { get ; private set ; }
@@ -86,7 +86,7 @@ public TypeAdapterSetter<TSource, TDestination> ForType<TSource, TDestination>()
8686
8787 public LambdaExpression CreateMapExpression ( TypeTuple tuple , MapType mapType )
8888 {
89- if ( ConcurencyEnviroment )
89+ if ( ConcurrencyEnvironment )
9090 {
9191 Configure . WaitOne ( - 1 ) ;
9292 /// AdaptMutex.WaitOne(-1, false);
@@ -110,7 +110,7 @@ public LambdaExpression CreateMapExpression(TypeTuple tuple, MapType mapType)
110110 }
111111 finally
112112 {
113- if ( ConcurencyEnviroment )
113+ if ( ConcurrencyEnvironment )
114114 {
115115 AdaptMutex . Set ( ) ;
116116 Configure . Set ( ) ;
@@ -325,6 +325,9 @@ public static class TypeAdapterConfig<TSource, TDestination>
325325 /// <returns></returns>
326326 public static TypeAdapterSetter < TSource , TDestination > NewConfig ( )
327327 {
328+ if ( TypeAdapterConfigFactory . GlobalSettings is IConfigConcurrency config )
329+ config . ConcurrencyEnvironment = false ;
330+
328331 return TypeAdapterConfigFactory . GlobalSettings . NewConfig < TSource , TDestination > ( ) ;
329332 }
330333
@@ -335,6 +338,9 @@ public static TypeAdapterSetter<TSource, TDestination> NewConfig()
335338 /// <returns></returns>
336339 public static TypeAdapterSetter < TSource , TDestination > ForType ( )
337340 {
341+ if ( TypeAdapterConfigFactory . GlobalSettings is IConfigConcurrency config )
342+ config . ConcurrencyEnvironment = false ;
343+
338344 return TypeAdapterConfigFactory . GlobalSettings . ForType < TSource , TDestination > ( ) ;
339345 }
340346
@@ -347,4 +353,45 @@ public static void Clear()
347353 TypeAdapterConfigFactory . GlobalSettings . Remove ( typeof ( TSource ) , typeof ( TDestination ) ) ;
348354 }
349355 }
356+
357+ public static class TypeAdapterConfigConcurrency < TSource , TDestination >
358+ {
359+ /// <summary>
360+ /// Creates a new configuration for mapping between the source and destination types.
361+ /// </summary>
362+ /// <returns></returns>
363+ public static TypeAdapterSetter < TSource , TDestination > NewConfig ( )
364+ {
365+ if ( TypeAdapterConfigFactory . GlobalSettings is IConfigConcurrency config )
366+ config . ConcurrencyEnvironment = true ;
367+
368+ return TypeAdapterConfigFactory . GlobalSettings . NewConfig < TSource , TDestination > ( ) ;
369+ }
370+
371+
372+ /// <summary>
373+ /// Creates a configuration for mapping between the source and destination types.
374+ /// </summary>
375+ /// <returns></returns>
376+ public static TypeAdapterSetter < TSource , TDestination > ForType ( )
377+ {
378+ if ( TypeAdapterConfigFactory . GlobalSettings is IConfigConcurrency config )
379+ config . ConcurrencyEnvironment = true ;
380+ return TypeAdapterConfigFactory . GlobalSettings . ForType < TSource , TDestination > ( ) ;
381+ }
382+
383+
384+ /// <summary>
385+ /// Clears the type mapping configuration for the specified source and destination types.
386+ /// </summary>
387+ public static void Clear ( )
388+ {
389+ TypeAdapterConfigFactory . GlobalSettings . Remove ( typeof ( TSource ) , typeof ( TDestination ) ) ;
390+ }
391+ }
392+
393+ internal interface IConfigConcurrency
394+ {
395+ public bool ConcurrencyEnvironment { get ; set ; }
396+ }
350397}
0 commit comments