如何检查接口属性的可见性?
我已经开始在 Delphi 2010 中编写 Web 服务,并进行单元测试以确保它们按计划运行。我的代码单元测试通过了,但一个 Web 服务方法在作为服务调用时(即通过 SoapUI)没有返回值。经过几个小时的代码搜索后,我发现这是因为我的返回对象的属性不在界面的已发布部分中;他们在公共区域。
有没有办法让我的单元测试检查对象的变量可见性,以便我将来可以避免这个问题?我试图找到一种使用 RTTI 的方法,但没有找到任何东西。
I have started writing web services in Delphi 2010 and am unit testing to make sure they function as planned. My unit tests of the code passed but one web service method didn’t return a value when called as a service (i.e. through SoapUI). After many hours of searching through the code I discovered it was because the properties on my return object weren’t in the published section of the interface; they were in the public section.
Is there a way for my unit tests to check variable visibility on objects so I can avoid this problem in the future? I was trying to find a way with RTTI but haven’t been able to find anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过尝试访问某个属性的 RTTI 来确定该属性是否已声明为已发布。公共财产没有 RTTI,而发布的财产则有。
类似这样的内容:
有关 RTTI 的更多信息,请参阅 Brian Long 的文章:http:// www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm
You can determine whether a property was declared published by attempting to access that property's RTTI. A public property has no RTTI, a published property does.
Something like this:
For more info on RTTI, see Brian Long's article: http://www.blong.com/Conferences/BorConUK98/DelphiRTTI/CB140.htm
您可以使用 RTTI 轻松完成此操作。您可以在 TypInfo 单元中使用经典的 RTTI 函数 GetPropInfo。如果它返回nil,则不存在该名称的已发布属性。或者您可以使用扩展 RTTI 查找它并检查可见性属性,这将告诉您它声明的可见性级别。
You can do it with RTTI easily enough. You can use the classic RTTI function GetPropInfo in the TypInfo unit. If it returns nil, then no published property by that name exists. Or you can look it up with extended RTTI and check the Visibility property, which will tell you what visibility level it's declared at.