How would you compare two POCO‘s, which are instances of the same type?
Assuming you only want to compare the public properties, which can be simple or complex types.
While discussing this shortly with a good friend, we came up with three naive options.
You can check them out on GitHub, but i’ll summarize them here:
- Manually compare properties
- I don’t think this is very future proof or maintenance friendly, because adding a property but forgetting to update the comparison algorithm is very real (as a professional mender I have a sixth sense for this kind of things)
- Compare serialized JSON string
- We didn’t come up with this, but kind of encountered this in production code. I think this solves the future proofing, but i’m wary of the performance implications.
- Compare via reflection
- This sounds obvious, we did wonder how far this rabbit hole goes when you have properties with a complex type, we foresee some comparison challenges.
Send a pull request if you got a crazy idea.