翻译List< TypeA>列出< TypeB> [英] Translate a List<TypeA> to List<TypeB>

查看:77
本文介绍了翻译List< TypeA>列出< TypeB>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理解了翻译的概念.用它在这样的表示层将DataModel Type转换为DTO type时工作正常.

Understood the concept of translate. Used it in converting a DataModel Type to DTO type for presentation layer like this and worked fine.

objTypeB = objTypeA.TranslateTo<clsTypeB>();

TypeA和TypeB之间的差异只是一些属性的数据类型,我在Property Set方法中将它们转换了.

Discrepancy between TypeA and TypeB was just the datatype of few properties and I converted them in the Property Set method.

但是在上面的实现中,如果源是List<TypeA>,我将遍历每个循环以转换为TypeB并将其添加到另一个List<TypeB>实例.是否可以做这样的事情:

But in the above implementation if the source is List<TypeA>, I have loop through each to translate to TypeB and add it another List<TypeB> instance. Is it possible to do something like this instead:

假设resultListAList<clsTypeA>

var resultListB = resultListA.TranslateTo<List<clsTypeB>>();

我尝试过,似乎没有转换.我得到一个空的resultListB.有任何简单的方法吗?

I tried and does not seem to convert. I get a empty resultListB. Any easy approach to this??

推荐答案

这应该做到:

var resultListB = resultListA.ConvertAll(x => x.TranslateTo<clsTypeB>());

这篇关于翻译List&lt; TypeA&gt;列出&lt; TypeB&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆