Copy two identical object with different namespaces (recursive reflection)

后端 未结 7 1424
我寻月下人不归
我寻月下人不归 2021-01-06 19:22

I\'m working in c# with several workspaces that have one specific class which his always the same in each workspace. I would like to be able have a copy of this class to be

7条回答
  •  再見小時候
    2021-01-06 20:16

    You either need to refactor all of your duplicate classes into a single shared class or implement a common interface that all of your various classes implement. If you really can't modify the underlying types, create a subclass for each that implements your common interface.

    Yes, you can do it with reflection... but you really shouldn't because you end up with brittle, error prone, code.

提交回复
热议问题