问题描述
理解了翻译的概念.用它在这样的表示层将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:
假设resultListA
是List<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< TypeA>列出< TypeB>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!