@@ -263,6 +263,42 @@ public static TDestination ValidateAndAdapt<TSource, TDestination>(this TSource
263263 }
264264 return source . Adapt < TDestination > ( config ) ;
265265 }
266+
267+
268+ /// <summary>
269+ /// Adapt the source object to a destination type using a temporary configuration.
270+ /// A new TypeAdapterConfig is created for this call, ensuring GlobalSettings remain unchanged.
271+ /// Safe for init-only properties and record types.
272+ /// </summary>
273+ /// <typeparam name="TDestination">Destination type.</typeparam>
274+ /// <param name="source">Source object to adapt.</param>
275+ /// <param name="configAction">Action to customize the temporary config.</param>
276+ /// <returns>Adapted destination object of type TDestination.</returns>
277+ public static TDestination Adapt < TDestination > ( this object ? source , Action < TypeAdapterConfig > configAction )
278+ {
279+ var config = TypeAdapterConfig . GlobalSettings . Clone ( ) ;
280+ configAction ( config ) ;
281+ return source . Adapt < TDestination > ( config ) ;
282+ }
283+
284+ /// <summary>
285+ /// Adapt the source object from TSource to TDestination using a dedicated TypeAdapterSetter.
286+ /// A temporary TypeAdapterConfig is created and configured via the setter.
287+ /// Safe for init-only properties and record types, without modifying GlobalSettings.
288+ /// </summary>
289+ /// <typeparam name="TSource">Source type.</typeparam>
290+ /// <typeparam name="TDestination">Destination type.</typeparam>
291+ /// <param name="source">Source object to adapt.</param>
292+ /// <param name="configAction">Action to customize the TypeAdapterSetter.</param>
293+ /// <returns>Adapted destination object of type TDestination.</returns>
294+ public static TDestination Adapt < TSource , TDestination > ( this object ? source , Action < TypeAdapterSetter < TSource , TDestination > > configAction )
295+ {
296+ var config = TypeAdapterConfig . GlobalSettings . Clone ( ) ;
297+ var setter = config . ForType < TSource , TDestination > ( ) ;
298+ configAction ( setter ) ;
299+ setter . Settings . Resolvers . Reverse ( ) ;
300+ return source . Adapt < TDestination > ( config ) ;
301+ }
266302 }
267303
268304 [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Minor Code Smell" , "S1104:Fields should not have public accessibility" , Justification = "<Pending>" ) ]
0 commit comments