AutoMapper.Extensions.EnumMapping
3.2.0
Prefix Reserved
dotnet add package AutoMapper.Extensions.EnumMapping --version 3.2.0
NuGet\Install-Package AutoMapper.Extensions.EnumMapping -Version 3.2.0
<PackageReference Include="AutoMapper.Extensions.EnumMapping" Version="3.2.0" />
paket add AutoMapper.Extensions.EnumMapping --version 3.2.0
#r "nuget: AutoMapper.Extensions.EnumMapping, 3.2.0"
// Install AutoMapper.Extensions.EnumMapping as a Cake Addin #addin nuget:?package=AutoMapper.Extensions.EnumMapping&version=3.2.0 // Install AutoMapper.Extensions.EnumMapping as a Cake Tool #tool nuget:?package=AutoMapper.Extensions.EnumMapping&version=3.2.0
AutoMapper.Extensions.EnumMapping
Summary
The AutoMapper.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
- AutoMapper (from version 10.0)
Installing AutoMapper.Extensions.EnumMapping
You should install AutoMapper.Extensions.EnumMapping with NuGet:
Install-Package AutoMapper.Extensions.EnumMapping
Or via the .NET Core command line interface:
dotnet add package AutoMapper.Extensions.EnumMapping
Either commands, from Package Manager Console or .NET Core CLI, will download and install AutoMapper.Extensions.EnumMapping. AutoMapper.Extensions.EnumMapping has no dependencies.
Usage
Install via NuGet first:
Install-Package AutoMapper.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, but it is possible to map by name calling MapByName()
or MapByValue()
.
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
AutoMapper 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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- AutoMapper (>= 12.0.0 && < 14.0.0)
NuGet packages (8)
Showing the top 5 NuGet packages that depend on AutoMapper.Extensions.EnumMapping:
Package | Downloads |
---|---|
FFCEI.Microservices
A free library for ASP.NET Core 6+ Microservices development, with Model, Model Repository, Entity Framework Core and common Web Api features like CORS, Json serialization fixes, Swagger generation, JWT Authentication for simple and objective microservices development |
|
Dst.Common.Domain
Package Description |
|
Conexus.Common
Package Description |
|
VRSPRO.Common.Interfaces
A set of internal generic classes and extensions for working with caches, databases, queues, message brokers, files, reflection, errors, , pagination, collections, strings, and ASP NET CORE. You can use this code in your projects as is. You can copy, modify and distribute it without any restrictions. You do not need to provide any copyrights or references. |
|
IF.APM.OpenTelemetry.Data.Mapping
Immersive Fusion Ingestion related Libraries. |
GitHub repositories
This package is not used by any popular GitHub repositories.