在 C# 中克隆 DTO
目前,为了克隆我的 DTO,我正在实现 IClonable,但这(以及克隆 ctor 等替代方案)意味着我需要将实现逻辑添加到我的(否则)纯数据对象中。
是否有更好的方法来克隆 DTO,或者包含克隆逻辑是否可以?
Currently to clone my DTOs I'm implementing IClonable, but this (and the alternatives like a clone ctor) mean that I need to add implementation logic into my (otherwise) data-only object.
Is there a better way to clone DTOs, or is including clone logic considered to be OK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种逻辑是如此基本,以至于我认为它被延伸为实现逻辑。以这种方式克隆可能更有意义:
我看来,不将克隆逻辑添加到 DTO 中是过度遵循架构模式的一个明显例子。
Such logic is so basic that I think it's stretching it to call it implementation logic. It may simply make much more sense to clone in this way:
Not adding cloning logic into DTOs would to me be an obvious example of following architectural patterns too far.