SparkyTools.AutoMapper 1.0.1

AutoMapper syntax helpers

There is a newer version of this package available.
See the version list below for details.
Install-Package SparkyTools.AutoMapper -Version 1.0.1
dotnet add package SparkyTools.AutoMapper --version 1.0.1
<PackageReference Include="SparkyTools.AutoMapper" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SparkyTools.AutoMapper --version 1.0.1
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)
MappedTo extension method

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

    Bar bar = Mapper.Map<Foo, Bar>(foo);

with:

    Bar bar = foo.MappedTo<Bar>();

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)
MappedTo extension method

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

    Bar bar = Mapper.Map<Foo, Bar>(foo);

with:

    Bar bar = foo.MappedTo<Bar>();

Release Notes

v1.0.1 - Target .NET Standard 1.1

Version History

Version Downloads Last updated
2.0.3 57 5/12/2019
2.0.2 85 4/11/2019
2.0.1 106 11/22/2018
2.0.0 95 11/22/2018
1.5.2 56 5/12/2019
1.5.1 93 4/13/2019
1.5.0 84 4/11/2019
1.4.0 106 10/31/2018
1.3.0 214 5/12/2018
1.2.0 302 4/27/2018
1.1.0 302 4/22/2018
1.0.1 198 4/12/2018
1.0.0 177 2/16/2018
Show less