Skip to content

v10.1.0-pre01

Pre-release
Pre-release

Choose a tag to compare

@DocSvartz DocSvartz released this 28 Jul 09:13
· 24 commits to v10.1.0 since this release

New features

DefaultValue() - Custom default value for Destination type


config.ForDestinationType<int>()
                .DefaultValue(x => 42);

int? src = null;


var result = src.Adapt<int>(config);  // result == 42

var result = src.Adapt<int>();  // By default result will be equal to 0 - the default value for type Int

MapUsing() - Map Property/Field with using Override type mapping settings

Unlike Map(), which is designed to specify an alternative source for a Property/Field, using MapUsing() you can set unique settings for mapping types for the specified Property/Field:

int? src = null;
var srcData = new NullablIData() { Data = null };

config.
  NewConfig<NullablIData, NullablIData>()
  .MapUsing(dest => dest.Data, src => src.Data, cfg =>
  {
    cfg.ReConfigurate()
    .DefaultValue(x => 42);
  });


var resultData = srcData.Adapt<NullableData>(config); // result.Data == 42

var result = src.Adapt<int?>(config); // result == null

Implementation Features

  1. Does not support ExtraSource/Flattening mapping - .Map(dest => dest, src => src.Props)

  2. By default Override type mapping settings has will contain all the settings, which are installed in the settings setter pipeline (merge default settings for a type and specific settings.)


// default settings setter

config.Default
config.ForDestinationType<TDestination>()

// specific settings setter
	
config.ForType<TSource,TDestination>() 
config.NewConfig<TSource,TSource>()

2.1) Additional behavior for Override type mapping settings

2.1.1) .ReConfigurate() - Allows you to set or override existing settings.

.MapUsing(dest => dest.Data, src => src.Data, cfg =>
{
    cfg.ReConfigurate()
    .DefaultValue(x => 42);
});

Note

Some settings cannot be overridden due to the way it is stored.

2.1.2) .SkipAllSettings(true) - create new config like using .NewConfig<TSource,TSource>() In this case, no default settings are applied.

.MapUsing(src => src.Data, dest => dest.Data,
cfg =>
{
    cfg.SkipAllSettings(true);
})

2.1.3) .SkipSettings() - Prevents the application of the selected settings

Caution

This setter will be removed in release.
If you need Skip the settings that can be accessed using this method, please leave a comment in this release discussion or submit a PR. Thanks!

.MapUsing(src => src.ArrayData, dest => dest.ListData,
cfg =>
{
    cfg.SkipSettings(x=>x.DestinationTransforms);
})

What's Changed

Full Changelog: v10.0.11...v10.1.0-pre01