interface property copy in c#

后端 未结 8 2203
一生所求
一生所求 2021-02-07 08:13

I\'ve been working with C# for many years now, but just come across this issue that\'s stumping me, and I really don\'t even know how to ask the question, so, to the example!

8条回答
  •  孤街浪徒
    2021-02-07 09:02

    If you encapsulate the common parts of the home and work address into a separate class it may make your life easier. Then you can simply copy across that property. This seems like better design to me.

    Alternatively, you may be able to hack together a solution with reflection and attributes where the value of the properties in one object are copied over to the matching (and marked) properties in the other. Of course this is not going to be a one-line solution either but it may be faster and more maintainable than others if you have a large set of properties.

提交回复
热议问题