SparkyTools.AutoMapper 2.0.4

Install-Package SparkyTools.AutoMapper -Version 2.0.4
dotnet add package SparkyTools.AutoMapper --version 2.0.4
<PackageReference Include="SparkyTools.AutoMapper" Version="2.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SparkyTools.AutoMapper --version 2.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SparkyTools.AutoMapper, 2.0.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SparkyTools.AutoMapper as a Cake Addin
#addin nuget:?package=SparkyTools.AutoMapper&version=2.0.4

// Install SparkyTools.AutoMapper as a Cake Tool
#tool nuget:?package=SparkyTools.AutoMapper&version=2.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

see also:


This package enables an alternate, less verbose syntax for some of the functions that "dot on" to AutoMapper "ForMember" functions, including .MapFrom, .NullSubstitute, .UseValue and .Ignore.

Without SparkyTools.AutoMapper:

    Mapper.Initialize(cfg => 
        cfg.CreateMap<Foo, Bar>()
            .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusCode))
            .ForMember(dest => dest.Comments, opt => opt.NullSubstitute("(none)"))
            .ForMember(dest => dest.IsImportant, opt => opt.UseValue(true))
            .ForMember(dest => dest.UniqueId, opt => opt.UseValue(Guid.NewGuid()))
            .ForMember(dest => dest.Useless, opt => opt.Ignore());

With SparkyTools.AutoMapper:

using SparkyTools.AutoMapper;
    Mapper.Initialize(cfg => 
        cfg.CreateMap<Foo, Bar>()
            .ForMember(dest => dest.Status).MapFrom(src => src.StatusCode)
            .ForMember(dest => dest.Comments).NullSubstitute("(none)")
            .ForMember(dest => dest.IsImportant).UseValue(true)
            .ForMember(dest => dest.UniqueId).UseValue(Guid.NewGuid())
            .ForMember(dest => dest.Useless).Ignore();

Ignoring members can be simplified even further.

.ForMember(dest => dest.Useless).Ignore()

can be coded as:

.IgnoreMember(dest => dest.Useless)

...or, to ignore multiple members:

.IgnoringMembers(dest => dest.Useless, dest => dest.Useless2, dest => dest.Useless3)
MappedTo extension methods

The package also contains an extension method that allows you to replace

    Bar bar = Mapper.Map<Foo, Bar>(foo); // with static Mapper
    Bar bar = mapper.Map<foo, Bar>(foo): // with IMapper instance

with:

    Bar bar = foo.MappedTo<Bar>(); // with static Mapper
    Bar bar = foo.MappedTo<Bar>(mapper); // with IMapper instance

AutoMapperConfigurationValidity

The Assert methods in this static class wrap Mapper.AssertConfigurationIsValid and IConfigurationProvider.AssertConfigurationIsValid with an exception handler that provides suggestions for dealing with unmapped properties.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.4 342 7/27/2019
2.0.3 317 5/12/2019
2.0.2 341 4/11/2019
2.0.1 420 11/22/2018
2.0.0 411 11/22/2018
1.5.3 314 7/27/2019
1.5.2 328 5/12/2019
1.5.1 331 4/13/2019
1.5.0 442 4/11/2019
1.4.0 428 10/31/2018
1.3.0 581 5/12/2018
1.2.0 699 4/27/2018
1.1.0 696 4/22/2018
1.0.1 612 4/12/2018
1.0.0 527 2/16/2018