Maicon
Maicon

Reputation: 51

Convert a list of one type to another

I have the following class:

  public class RelatorioResumoMovimentacaoECFDTO
  {
        [DataMember]
        public IList<AliquotaRelatorioMapaResumoDTO> 
        Aliquotas { get{return     MovimentacaoECF_Id.TotalizadoresParciais.????} }

        [DataMember]
        public MovimentacaoECF MovimentacaoECF_Id { get; set; }
  }

I need to convert the list "MovimentacaoECF_Id.TotalizadoresParciais" on a different list ...

something I could report that the X field of the list one is the Y field of the list two type when I convert KeyPairValue in dictionary

var dictionary = list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value);

Upvotes: 0

Views: 2013

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064114

It is a little unclear what you are trying to do, but in the general case, Select may be useful here:

return MovimentacaoECF_Id.TotalizadoresParciais.Select(x =>
            new AliquotaRelatorioMapaResumoDTO {
               Foo = x.Foo,
               Name = x.SomeName,
               Id = x.Whatever,
               // ...
       }).ToList();

Upvotes: 4

Related Questions