VOOZH about

URL: https://www.nuget.org/packages/SyZero.AutoMapper/

⇱ NuGet Gallery | SyZero.AutoMapper 1.1.9




👁 Image
SyZero.AutoMapper 1.1.9

dotnet add package SyZero.AutoMapper --version 1.1.9
 
 
NuGet\Install-Package SyZero.AutoMapper -Version 1.1.9
 
 
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="SyZero.AutoMapper" Version="1.1.9" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SyZero.AutoMapper" Version="1.1.9" />
 
Directory.Packages.props
<PackageReference Include="SyZero.AutoMapper" />
 
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 SyZero.AutoMapper --version 1.1.9
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SyZero.AutoMapper, 1.1.9"
 
 
#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 SyZero.AutoMapper@1.1.9
 
 
#: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=SyZero.AutoMapper&version=1.1.9
 
Install as a Cake Addin
#tool nuget:?package=SyZero.AutoMapper&version=1.1.9
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

SyZero.AutoMapper

SyZero 框架的 AutoMapper 集成模块,提供对象映射自动配置。

📦 安装

dotnet add package SyZero.AutoMapper

✨ 特性

  • 🚀 自动扫描 - 自动扫描并注册所有 Profile
  • 💾 依赖注入 - 无缝集成 Microsoft DI
  • 🔒 类型安全 - 编译时类型检查
  • 📦 集合映射 - 内置 AutoMapper.Collection 支持
  • 🎯 多目标框架 - 支持 net8.0、net9.0

🚀 快速开始

注册服务

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// 添加SyZero
builder.AddSyZero();

// 方式1 - 自动扫描所有程序集
builder.Services.AddSyZeroAutoMapper();

// 方式2 - 指定程序集
builder.Services.AddSyZeroAutoMapper(typeof(UserProfile).Assembly);

// 方式3 - 多个程序集
builder.Services.AddSyZeroAutoMapper(
 typeof(UserProfile).Assembly,
 typeof(OrderProfile).Assembly
);

// 方式4 - 自定义配置
builder.Services.AddSyZeroAutoMapper(cfg =>
{
 cfg.AllowNullCollections = true;
 cfg.AllowNullDestinationValues = false;
}, typeof(UserProfile).Assembly);

var app = builder.Build();
// 使用SyZero
app.UseSyZero();
app.Run();

使用示例

public class UserProfile : Profile
{
 public UserProfile()
 {
 CreateMap<User, UserDto>();
 CreateMap<CreateUserInput, User>();
 
 // 集合映射(由 AutoMapper.Collection 提供)
 CreateMap<User, UserDto>()
 .EqualityComparison((src, dest) => src.Id == dest.Id);
 }
}

public class UserService
{
 private readonly IObjectMapper _mapper;

 public UserService(IObjectMapper mapper)
 {
 _mapper = mapper;
 }

 public UserDto GetUser(User user)
 {
 return _mapper.Map<UserDto>(user);
 }
 
 public void UpdateUser(UserDto dto, User user)
 {
 _mapper.Map(dto, user);
 }
}

📖 API 说明

IObjectMapper 接口(SyZero 抽象)

方法 说明
Map<TDestination>(source) 将源对象映射到目标类型
Map<TSource, TDestination>(source, dest) 映射到现有对象

IMapper 接口(AutoMapper 原生)

方法 说明
Map<TDestination>(source) 将源对象映射到目标类型
Map<TSource, TDestination>(source, dest) 映射到现有对象
Map(source, sourceType, destType) 动态类型映射
ProjectTo<TDestination>(queryable) IQueryable 投影映射

所有映射操作都是线程安全的


🔧 高级用法

自定义值转换

public class UserProfile : Profile
{
 public UserProfile()
 {
 CreateMap<User, UserDto>()
 .ForMember(dest => dest.FullName, 
 opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"));
 }
}

条件映射

CreateMap<User, UserDto>()
 .ForMember(dest => dest.Email, 
 opt => opt.Condition(src => src.IsEmailVerified));

⚠️ 注意事项

  1. Profile 类 - 所有映射配置应在 Profile 类中定义
  2. 循环引用 - 注意处理对象间的循环引用
  3. 性能 - 避免在热路径中使用动态映射

📄 许可证

MIT License - 详见

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (2)

Showing the top 2 NuGet packages that depend on SyZero.AutoMapper:

Package Downloads
SyZero.Example1.Application

Package Description

SyZero.Example2.Application

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.9 117 4/19/2026
1.1.9-dev.2 54 4/19/2026
1.1.9-dev.1 61 4/17/2026
1.1.8 111 4/17/2026
1.1.6 114 4/17/2026
1.1.6-dev.1 53 4/17/2026
1.1.5 125 4/13/2026
1.1.5-dev.3 63 4/13/2026
1.1.5-dev.2 82 2/11/2026
1.1.5-dev.1 70 1/29/2026
1.1.4 152 1/2/2026
1.1.4-dev.2 82 1/2/2026
1.1.4-dev.1 78 12/30/2025
1.1.3 135 12/30/2025
1.1.3-dev.6 69 12/30/2025
1.1.3-dev.3 133 1/19/2024
1.1.3-dev.2 207 11/3/2023
1.1.3-dev.1 214 3/21/2023
1.1.2 409 3/15/2023
1.1.2-dev.108.29344 221 3/15/2023
Loading failed