Vane.Mapper
1.0.1
dotnet add package Vane.Mapper --version 1.0.1
NuGet\Install-Package Vane.Mapper -Version 1.0.1
<PackageReference Include="Vane.Mapper" Version="1.0.1" />
<PackageVersion Include="Vane.Mapper" Version="1.0.1" />
<PackageReference Include="Vane.Mapper" />
paket add Vane.Mapper --version 1.0.1
#r "nuget: Vane.Mapper, 1.0.1"
#:package Vane.Mapper@1.0.1
#addin nuget:?package=Vane.Mapper&version=1.0.1
#tool nuget:?package=Vane.Mapper&version=1.0.1
Vane.Mapper
Object mapping with two implementations of one declaration: a runtime expression-tree engine and an optional compile-time source generator. Namespace Vane.Mapping, targets net8.0 / net10.0 / net11.0, zero third-party dependencies.
同一份声明、两条互不查询的实现路径:运行时表达式树引擎 + 可选的编译期源生成器。命名空间 Vane.Mapping,支持 net8.0 / net10.0 / net11.0,核心包零第三方依赖。
Install / 安装
dotnet add package Vane.Mapper # latest stable / 最新稳定版
dotnet add package Vane.Mapper.Generator # AOT / trimming
# reproducible builds: pin an exact version / 可重现构建请锁定具体版本
# dotnet add package Vane.Mapper --version 1.0.1
省略 --version 取 NuGet 上的最新稳定版;生产与 CI 请显式锁定版本号(如 --version 1.0.1),不要用浮动区间,否则同一次构建在两台机器上可能解析到不同包。
Quick start / 快速开始
using Vane.Mapping;
var dto = Mapper.Map<User, UserDto>(user); // new instance / 新建目标
Mapper.Map(user, existingDto); // write into existing / 写入已有实例
Generator path / 生成器路径:
[Mapper(UseSourceGenerator = true)]
public class UserDto { public string Name { get; set; } = ""; public int Age { get; set; } }
public partial class UserMapper
{
public partial UserDto Map(User source);
}
Configure at startup / 启动期配置
MapperBuilder mirrors IServiceCollection: mutable during startup, frozen by Build() into an immutable, thread-safe IMapperRuntime.
MapperBuilder 照 IServiceCollection 的形状:启动期可变,Build() 冻结成不可变、线程安全的 IMapperRuntime。
var runtime = new MapperBuilder()
.Defaults(d => d.IgnoreCase())
.Add<Order, OrderDto>(m => m.ForMember(d => d.Total, s => s.Amount))
.Build();
Precompile at startup / 启动期预编译
Expressions are compiled on first use. Prewarm() moves that off the request path (only already-registered pairs, idempotent, throws the first failing pair at startup; return value = pairs compiled).
表达式在首次映射时才编译;Prewarm() 把这段成本挪到启动期(只处理已登记的类型对、幂等、失败在启动期直接抛,返回实际编译的对数)。
var compiled = runtime.Prewarm(); // pairs compiled / 编译的对数
runtime.Prewarm(includeCopy: true); // also "write into existing" / 连写入委托一起准备
var projections = runtime.PrewarmProjections(); // query projections built / 提前构建查询投影表达式树
Measured: first pair 68–87 ms → 0.01–4.8 ms. Not available under AOT — use the generator there. 实测首对 68–87 ms → 0.01–4.8 ms。AOT 下不可用,请走生成器。
PrewarmProjections() prepares the Expression you pass to an ORM. It builds the tree but never compiles it, so EF Core translates it into exactly the same SQL as on a cold start (verified against real SQLite). Default shape only, idempotent, untranslatable pairs throw at startup naming the member.
PrewarmProjections() 准备交给 ORM 的那个 Expression:只构建、不编译,EF Core 翻译出的 SQL 与冷启动一致(有 SQLite 真库用例验证);只覆盖默认形态、幂等,不可翻译的对在启动期抛异常并点名成员。
Which path / 路径选择
| Runtime | Generator | |
|---|---|---|
| Features | full (deep copy, hooks, projection) | flat / nested / collections |
| NativeAOT / trimming | not supported | supported |
| Entry | Mapper.Map / IMapperRuntime |
partial Map |
The runtime path is the default; the generator path is the only option for NativeAOT or TrimMode=link.
运行时路径功能最全;NativeAOT 与裁剪只能走生成器路径。
Docs / 文档
- Manual / 开发手册:https://gitee.com/netcasewqs/Vane.Mapper/blob/master/docs/开发手册.md
- Diagnostics / 诊断码:https://gitee.com/netcasewqs/Vane.Mapper/blob/master/docs/诊断.md
- Projection / 投影(白名单与边界见 §4.10):https://gitee.com/netcasewqs/Vane.Mapper/blob/master/docs/开发手册.md
- Release notes / 发布说明:https://gitee.com/netcasewqs/Vane.Mapper/blob/master/docs/RELEASE-1.0.1.md
MIT, license text ships with the package.
| 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 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 is compatible. 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Vane.Mapper:
| Package | Downloads |
|---|---|
|
Vane.Mapper.DependencyInjection
Vane.Mapper 的 Microsoft.Extensions.DependencyInjection 薄适配;核心库保持零外部依赖。 |
|
|
Vane.Mapper.Container
Vane.Mapper 的 Vane.Container 原生注册表适配;核心库保持零外部依赖。 |
GitHub repositories
This package is not used by any popular GitHub repositories.
1.0.1:修复 MapHandle.Backend 在 CopyMode.Deep 降级后报错后端的问题;生成器集合发射改为预分配+循环(嵌套分配 816 B→744 B);生成器新增 partial void Map(TFrom, TTo) 写入重载。详见 https://gitee.com/netcasewqs/Vane.Mapper/blob/master/docs/RELEASE-1.0.1.md