EasilyNET.ExpressMapper 3.24.1103

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasilyNET.ExpressMapper --version 3.24.1103                
NuGet\Install-Package EasilyNET.ExpressMapper -Version 3.24.1103                
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="EasilyNET.ExpressMapper" Version="3.24.1103" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.ExpressMapper --version 3.24.1103                
#r "nuget: EasilyNET.ExpressMapper, 3.24.1103"                
#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.
// Install EasilyNET.ExpressMapper as a Cake Addin
#addin nuget:?package=EasilyNET.ExpressMapper&version=3.24.1103

// Install EasilyNET.ExpressMapper as a Cake Tool
#tool nuget:?package=EasilyNET.ExpressMapper&version=3.24.1103                

EasilyNET.ExpressMapper

本项目从 RosTransNadzor/ExpressMapper 复刻,原项目好像没有 Nuget 包,所以自己复制代码到这里,并且发布到 Nuget 上.添加了注释以及修改了部分拼写错误的代码.

ExpressMapper

ExpressMapper 是一个轻量级且易于使用的对象到对象映射库,适用于 .NET,旨在简化在应用程序的各个层之间转换数据的过程.它提供了可自定义的映射配置、属性忽略、构造函数映射和复合配置,以轻松处理复杂的场景.

<details> <summary style="font-size: 14px">English</summary>

ExpressMapper is a lightweight and easy-to-use object-to-object mapping library for .NET, designed to streamline the process of transforming data between various layers of your application. It offers customizable mapping configurations, property ignoring, constructor mapping, and composite configurations to handle complex scenarios with ease.

</details>

Features | 特性

  • 可自定义的映射配置: 通过细粒度控制定义源属性和目标属性之间的映射.
  • 忽略特定属性: 在映射过程中选择忽略源或目标端的属性.
  • 构造函数映射: 在实例化目标对象时使用特定的构造函数,适用于复杂对象.
  • 复合配置: 在单个配置类中管理不同类型的多个映射.

<details> <summary style="font-size: 14px">English</summary>

  • Customizable Mapping Configurations: Define mappings between source and destination properties with fine-grained control.
  • Ignore Specific Properties: Choose to ignore properties on either the source or destination side during the mapping.
  • Constructor Mapping: Use specific constructors when instantiating destination objects, useful for complex objects.
  • Composite Configurations: Manage multiple mappings for different types within a single configuration class.

</details>

Installation | 安装

Install ExpressMapper via NuGet:

Install-Package EasilyNET.ExpressMapper

Getting Started | 入门

要使用 ExpressMapper,首先定义源类和目标类,然后使用提供的配置类配置映射.

<details> <summary style="font-size: 14px">English</summary>

To use ExpressMapper, start by defining your source and destination classes, and then configure the mappings using the provided configuration classes.

</details>

Example Classes | 示例类

public class User
{
    public string Name { get; set; }
    public string Description { get; set; }
}

public class UserDto
{
    public string UserName { get; set; }
    public string AdditionalInfo { get; set; }
}

Customizable Mapping Configurations | 可自定义的映射配置

定义不同类之间的属性映射方式:

<details> <summary style="font-size: 14px">English</summary>

Define how properties are mapped between different classes:

</details>

file class UserConfig : MapperConfig<User, UserDto>
{
    public override void Configure(IMappingConfigurer<User, UserDto> configurer)
    {
        configurer
            .Map(dto => dto.UserName, us => us.Name);
    }
}

Ignoring Properties | 忽略属性

在映射过程中排除某些属性:

<details> <summary style="font-size: 14px">English</summary>

Exclude certain properties from the mapping process:

</details>

file class UserConfig : MapperConfig<User, UserDto>
{
    public override void Configure(IMappingConfigurer<User, UserDto> configurer)
    {
        configurer
            .Map(dto => dto.UserName, us => us.Name)
            .IgnoreDest(dto => dto.UserName)
            .IgnoreSource(us => us.Description);
    }
}

Constructor Mapping | 构造函数映射

指定使用带有特定参数的构造函数:

<details> <summary style="font-size: 14px">English</summary>

Specify the use of constructors with specific parameters:

</details>

configurer.WithConstructor<string, string>();

Composite Configurations | 复合配置

将多个配置组合到一个配置类中:

<details> <summary style="font-size: 14px">English</summary>

Combine multiple configurations into a single configuration class:

</details>

file class GeneralConfig : CompositeConfig
{
    public override void Configure()
    {
        NewConfiguration<Address, AddressDto>()
            .IgnoreDest(dto => dto.City);

        NewConfiguration<Product, ProductDto>()
            .Map(dto => dto.Id, product => product.ProductId);
    }

}

Example Usage | 示例用法

public static class Program
{
    static void Main(string[] args)
    {
        var mapper = Mapper.Create<GeneralConfig, UserConfig>();
        var user = new User
        {
            Description = "desc"
        };
        var dto = mapper.Map<User, UserDto>(user);
        Console.WriteLine(dto);
    }
}

这个示例演示了如何创建一个包含组合配置的映射器,并将 User 对象映射到 UserDto.

<details> <summary style="font-size: 14px">English</summary>

This example demonstrates how to create a mapper with combined configurations and map a User object to a UserDto.

</details>

Conclusion | 结论

ExpressMapper 为 .NET 应用程序中的对象到对象映射提供了一个灵活且强大的解决方案.无论是简单的 DTO 还是复杂的对象,都可以根据您的具体需求自定义映射.

<details> <summary style="font-size: 14px">English</summary>

ExpressMapper provides a flexible and powerful solution for object-to-object mapping in .NET applications. Customize your mappings to fit your specific needs, whether it's for simple DTOs or complex objects.

For more information, please refer to the official documentation or check out the source code examples.

</details>

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 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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
3.24.1105.111 21 11/5/2024
3.24.1103.31 39 11/2/2024
3.24.1103 39 11/2/2024
3.24.1031.135 42 10/31/2024
3.24.1031.112 33 10/31/2024
3.24.1031.104 33 10/31/2024
3.24.1029.142 76 10/29/2024
3.24.1025.30 156 10/24/2024
3.24.1022.142 54 10/22/2024
3.24.1018.204 124 10/18/2024
3.24.1018.175 126 10/18/2024
3.24.1018.166 118 10/18/2024
3.24.1018.93 128 10/18/2024
3.24.1017.42 78 10/16/2024
3.24.1016.161 79 10/16/2024
3.24.1015.231 71 10/15/2024
3.24.1015.14 75 10/14/2024
3.24.1012.114 83 10/12/2024
3.24.1009.115 81 10/9/2024
3.24.1008.160 74 10/8/2024
3.24.1008.133 72 10/8/2024
3.24.1007.185 76 10/7/2024
3.24.1003.33 88 10/2/2024
3.24.1002.162 93 10/2/2024
3.24.929.143 214 9/29/2024
3.24.929.141 84 9/29/2024
3.24.929.131 84 9/29/2024
3.24.929.122 87 9/29/2024
3.24.926.184 88 9/26/2024
3.24.926.182 82 9/26/2024
3.24.926.175 82 9/26/2024
3.24.924.160 126 9/24/2024
3.24.924.133 107 9/24/2024
3.24.924.124 90 9/24/2024
3.24.924.10 88 9/23/2024
3.24.924.1 83 9/23/2024
3.24.923.234 81 9/23/2024
3.24.923.232 89 9/23/2024
3.24.923.155 107 9/23/2024
3.24.919.92 119 9/19/2024
3.24.914.125 253 9/14/2024
3.24.914.115 98 9/14/2024
3.24.914.111 102 9/14/2024
3.24.911.95 102 9/11/2024
3.24.908.215 87 9/8/2024
3.24.904.200 98 9/4/2024
3.24.828.163 273 8/28/2024
3.24.820.173 113 8/20/2024
3.24.820.172 119 8/20/2024