深度对象比较 Delphi
在 Delphi 中寻找一种方法来为我进行深度对象比较,最好是基于 2010 RTTI,因为我的对象不是从 TComponent
继承的。我正在 DUnit 中开发一个测试框架,需要一些可靠的东西来准确指出哪个字段导致了问题(序列化比较让它有点模糊)。
Looking for a way in Delphi to do deep object comparison for me, preferably 2010 RTTI based as my objects don't inherit from TComponent
. I'm developing a test framework in DUnit
and need something solid which will point out exactly which field is causing problems (serialization comparison leaves it a bit vague).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己解决了这个问题,作为 TObject 的类助手实现,因此如果人们需要的话可以在任何地方使用。 D2010 及更高版本由于 RTTI,但您也许可以将其转换为使用原始 RTTI 内容。
下面的代码可能有错误,因为我最初是针对 DUnit 的,其中进行了大量检查而不是更改结果,并且不支持 TCollections 或大量其他特殊情况,但可以通过使用 if-elseif-then 进行调整中间切换。
如果您有任何建议和补充,请随时发表评论,以便我可以将它们添加到其中,以便其他人可以使用它。
祝
巴里编码愉快
Sort of solved this myself, implemented as a class helper for TObject so can be used everywhere if people want it. D2010 and up due to RTTI but you may be able to convert it to use original RTTI stuff.
Code below may be buggy as originally mine was for DUnit and had lots of checks in it instead of changing the result and doesn't support TCollections or a load of other special cases but can be adapted for that by using the if-elseif-then switch in the middle.
If you have any suggestions and additions please don't hesitate to comment so I can add them to it so other people can use this.
Have fun coding
Barry
考虑使用 OmniXML 持久性。
对于 XML 差异,我使用 OmniXML 编写了一个实用程序来执行 XML 差异,并且有许多 XML 比较工具。
我使用 OmniXML 制作了一个 XML 差异工具来实现这个目的,它对我来说非常有用。不幸的是,该工具包含许多特定于领域的内容,并且是闭源的,属于前雇主,因此我无法发布代码。
我的比较工具有一个简单的算法:
Consider using OmniXML persistence.
For XML differencing, I have written a utility using OmniXML that will do an XML diff, and there are many XML comparison tools out there.
I used OmniXML to do an XML differencing tool for exactly this purpose, and it worked great for me. Unfortunately that tool contains many domain specific things and is closed-source and belongs to a former employer so I cannot post the code.
My comparision tool had a simple algorithm: