c# - 使用私有集自动映射目标集合属性
问题描述
public sealed class ParentSource
{
public string Name { get; }
public List<ChildSource> Children { get; }
public ParentSource(string name)
{
Name = name;
Children = new List<ChildSource>();
}
}
public sealed class ChildSource
{
public string Name { get; }
public ChildSource(string name)
{
Name = name;
}
}
public sealed class ParentDestination
{
public string Name { get; }
public List<ChildDestination> Children { get; }
public ParentDestination(string name)
{
Name = name;
Children = new List<ChildDestination>();
}
}
public sealed class ChildDestination
{
public string Name { get; }
public ChildDestination(string name)
{
Name = name;
}
}
据我了解,我需要的只是以下映射:
CreateMap<ParentSource, ParentDestination>();
CreateMap<ChildSource, ChildDestination>();
调用映射:
var parentSource = new ParentSource("parent");
var childSource = new ChildSource("child");
parentSource.Children.Add(childSource);
var parentDestination = mapper.Map<ParentSource, ParentDestination>(parentSource);
除非我将公共设置器添加到 Children 属性,否则目标父级的子集合不包含任何成员。如果没有公共二传手,我怎样才能完成这项工作?
解决方案
推荐阅读
- session - 没有 Cookie / 没有 IP 跟踪访客
- java - sun.security.ssl.Alert.createSSLException 使用 apache commons library 进行 post call
- javascript - ajax 调用会减慢前端的速度吗?
- javascript - 用于 YAML 前端的 Javascript 正则表达式
- python - 启动器中的致命错误:无法使用“”创建进程
- html - 根据该图像坐标将图像放在 VueJS/Vuetify 中的另一个上
- php - 将 id 值提交到购物车页面 php
- c++ - 通过它的模板类重载 C++ 模板类方法
- node.js - Electron - 未捕获的错误:EROFS:只读文件系统
- c# - 我怎样才能钳制旋转?