MagicMapper.Extensions.EnumMapping 1.0.0

dotnet add package MagicMapper.Extensions.EnumMapping --version 1.0.0
                    
NuGet\Install-Package MagicMapper.Extensions.EnumMapping -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MagicMapper.Extensions.EnumMapping" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MagicMapper.Extensions.EnumMapping" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MagicMapper.Extensions.EnumMapping" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MagicMapper.Extensions.EnumMapping --version 1.0.0
                    
#r "nuget: MagicMapper.Extensions.EnumMapping, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MagicMapper.Extensions.EnumMapping@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MagicMapper.Extensions.EnumMapping&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MagicMapper.Extensions.EnumMapping&version=1.0.0
                    
Install as a Cake Tool

MagicMapper.Extensions.EnumMapping

CI NuGet NuGet MyGet (dev)

Summary

The MagicMapper.Extensions.EnumMapping library gives you control about your enum values mappings. It is possible to create a custom type converter for every enum.

This library supports mapping enums values like properties.

Dependencies

Installing MagicMapper.Extensions.EnumMapping

You should install MagicMapper.Extensions.EnumMapping with NuGet:

Install-Package MagicMapper.Extensions.EnumMapping

Or via the .NET Core command line interface:

dotnet add package MagicMapper.Extensions.EnumMapping

Either commands, from Package Manager Console or .NET Core CLI, will download and install MagicMapper.Extensions.EnumMapping. MagicMapper.Extensions.EnumMapping has no dependencies.

Usage

Install via NuGet first: Install-Package MagicMapper.Extensions.EnumMapping

To use it:

For method CreateMap this library provide a ConvertUsingEnumMapping method. This method add all default mappings from source to destination enum values.

If you want to change some mappings, then you can use MapValue method. This is a chainable method.

Default the enum values are mapped by value (MapByValue()), but it is possible to map by name calling MapByName(). For enums which does not have same values and names, you can use MapByCustom(). Then you have to add a MapValue for every source enum value.

using AutoMapper.Extensions.EnumMapping;

public enum Source
{
    Default = 0,
    First = 1,
    Second = 2
}

public enum Destination
{
    Default = 0,
    Second = 2
}

internal class YourProfile : Profile
{
    public YourProfile()
    {
        CreateMap<Source, Destination>()
            .ConvertUsingEnumMapping(opt => opt
		// optional: .MapByValue() or MapByName(), without configuration MapByValue is used
		.MapValue(Source.First, Destination.Default))
            .ReverseMap(); // to support Destination to Source mapping, including custom mappings of ConvertUsingEnumMapping
    }
}
    ...

Testing

MagicMapper provides a nice tooling for validating typemaps. This library adds an extra EnumMapperConfigurationExpressionExtensions.EnableEnumMappingValidation extension method to extend the existing AssertConfigurationIsValid() method to validate also the enum mappings.

To enable testing the enum mapping configuration:


public class MappingConfigurationsTests
{
    [Fact]
    public void WhenProfilesAreConfigured_ItShouldNotThrowException()
    {
        // Arrange
        var config = new MapperConfiguration(configuration =>
        {
            configuration.EnableEnumMappingValidation();

            configuration.AddMaps(typeof(AssemblyInfo).GetTypeInfo().Assembly);
        });
		
        // Assert
        config.AssertConfigurationIsValid();
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.0.0 32 4/5/2026