EasilyNET.ExpressMapper
3.24.1121.183
dotnet add package EasilyNET.ExpressMapper --version 3.24.1121.183
NuGet\Install-Package EasilyNET.ExpressMapper -Version 3.24.1121.183
<PackageReference Include="EasilyNET.ExpressMapper" Version="3.24.1121.183" />
paket add EasilyNET.ExpressMapper --version 3.24.1121.183
#r "nuget: EasilyNET.ExpressMapper, 3.24.1121.183"
// Install EasilyNET.ExpressMapper as a Cake Addin #addin nuget:?package=EasilyNET.ExpressMapper&version=3.24.1121.183 // Install EasilyNET.ExpressMapper as a Cake Tool #tool nuget:?package=EasilyNET.ExpressMapper&version=3.24.1121.183
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 | Versions 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. |
-
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.1121.183 | 92 | 11/21/2024 |
3.24.1120.183 | 84 | 11/20/2024 |
3.24.1119.31 | 86 | 11/18/2024 |
3.24.1115.143 | 72 | 11/15/2024 |
3.24.1113.100 | 87 | 11/13/2024 |
3.24.1112.125 | 168 | 11/12/2024 |
3.24.1107.140 | 90 | 11/7/2024 |
3.24.1107.54 | 74 | 11/7/2024 |
3.24.1107.34 | 85 | 11/7/2024 |
3.24.1105.111 | 88 | 11/5/2024 |
3.24.1103.31 | 97 | 11/2/2024 |
3.24.1103 | 89 | 11/2/2024 |
3.24.1031.135 | 97 | 10/31/2024 |
3.24.1031.112 | 87 | 10/31/2024 |
3.24.1031.104 | 76 | 10/31/2024 |
3.24.1029.142 | 89 | 10/29/2024 |
3.24.1025.30 | 187 | 10/24/2024 |
3.24.1022.142 | 71 | 10/22/2024 |
3.24.1018.204 | 136 | 10/18/2024 |
3.24.1018.175 | 139 | 10/18/2024 |
3.24.1018.166 | 130 | 10/18/2024 |
3.24.1018.93 | 142 | 10/18/2024 |
3.24.1017.42 | 89 | 10/16/2024 |
3.24.1016.161 | 91 | 10/16/2024 |
3.24.1015.231 | 86 | 10/15/2024 |
3.24.1015.14 | 88 | 10/14/2024 |
3.24.1012.114 | 99 | 10/12/2024 |
3.24.1009.115 | 93 | 10/9/2024 |
3.24.1008.160 | 88 | 10/8/2024 |
3.24.1008.133 | 91 | 10/8/2024 |
3.24.1007.185 | 88 | 10/7/2024 |
3.24.1003.33 | 109 | 10/2/2024 |
3.24.1002.162 | 107 | 10/2/2024 |
3.24.929.143 | 227 | 9/29/2024 |
3.24.929.141 | 94 | 9/29/2024 |
3.24.929.131 | 92 | 9/29/2024 |
3.24.929.122 | 96 | 9/29/2024 |
3.24.926.184 | 101 | 9/26/2024 |
3.24.926.182 | 93 | 9/26/2024 |
3.24.926.175 | 94 | 9/26/2024 |
3.24.924.160 | 136 | 9/24/2024 |
3.24.924.133 | 118 | 9/24/2024 |
3.24.924.124 | 100 | 9/24/2024 |
3.24.924.10 | 100 | 9/23/2024 |
3.24.924.1 | 97 | 9/23/2024 |
3.24.923.234 | 96 | 9/23/2024 |
3.24.923.232 | 104 | 9/23/2024 |
3.24.923.155 | 121 | 9/23/2024 |
3.24.919.92 | 132 | 9/19/2024 |
3.24.914.125 | 268 | 9/14/2024 |
3.24.914.115 | 113 | 9/14/2024 |
3.24.914.111 | 113 | 9/14/2024 |
3.24.911.95 | 111 | 9/11/2024 |
3.24.908.215 | 98 | 9/8/2024 |
3.24.904.200 | 107 | 9/4/2024 |
3.24.828.163 | 284 | 8/28/2024 |
3.24.820.173 | 124 | 8/20/2024 |
3.24.820.172 | 128 | 8/20/2024 |