How to convert one type to another using reflection?

前端 未结 3 1521
臣服心动
臣服心动 2021-01-25 03:29

I have a two types that are very similar (i.e. the member names are very similar).

Is there an elegant way to copy one type to another, without having to copy each indi

3条回答
  •  死守一世寂寞
    2021-01-25 04:20

    Use something like AutoMapper for that. It will allow you to simply define that class OptionsEnt should be mapped to FromCsvFile and if they have the properties with same names and types then you won't need to define anything else.

    Otherwise you'll have to iterate by properties.

提交回复
热议问题