Is there a better way to implment Equals for object with lots of fields?

后端 未结 4 2047
醉梦人生
醉梦人生 2021-01-15 09:15

see also Hows to quick check if data transfer two objects have equal properties in C#?

I have lot of Data Transfer Objects (DTO) tha

4条回答
  •  遥遥无期
    2021-01-15 09:25

    Edit: sorry, I didn't notice that you are asking for serialization testing. So this approach definitely doesn't work for you.


    There is another "dirty" way. If your object is serializable anyway, you can serialize them and compare the resulting streams.

    This is rather slow, but should be quite reliable and easy to implement.

    We are doing this sometimes to check if someone changed any data in an editor.

提交回复
热议问题