Generic C# Copy Constructor

前端 未结 5 1388
再見小時候
再見小時候 2021-01-31 10:55

What would be the best way to write a generic copy constructor function for my c# classes? They all inherit from an abstract base class so I could use reflection to map the prop

5条回答
  •  悲&欢浪女
    2021-01-31 11:15

    You can create a shallow copy efficiently with reflection by pre-compiling it, for example with Expression. For example, like so.

    For deep copies, serialization is the most reliable approach.

提交回复
热议问题