VFP 类可以在运行时获取它自己的方法的集合吗?
这就是我想要在 Visual FoxPro 中完成的任务。我想编写一个父 UnitTest 类,可以对其进行子类化以创建单独的单元测试。我希望父 UnitTest 可以有一个 MainMethod 来检查自身,然后查找并执行它自己的所有以“test_”开头的方法。
这样我就可以在单元测试中继续编写适当命名的函数,并且父级将知道如何运行它们,而无需我提供任何额外的输入。但是,如果子类没有明确定义方法名称的集合或与此相关的内容(这正是我希望避免的),我无法找到任何方法在运行时从 VFP 获取此信息。
这是一个基本的存根:
define class UnitTest as custom && would be abstract if VFP supported that
procedure MainMethod()
&& run all methods that begin with test_
endproc
enddefine
define class AUnitTest as UnitTest
procedure test_thingA()
...
endproc
procedure test_thingB()
...
endproc
enddefine
喜欢任何人关于如何从父级获取子方法的想法。 (也对更好的实现想法持开放态度,如果我的想法是错误的,我认为我想要的基本想法是明确的)。
非常感谢!
Here's what I'm trying to accomplish, in Visual FoxPro. I want to write a parent UnitTest class, that can be subclassed to create individual unit tests. I am hoping that the parent UnitTest can have a MainMethod which examines itself, and then finds and executes all of it's own methods which begin with "test_".
This way I can go forward writing appropriately named functions in my unit tests, and the parent will know how to run them without any additional input from me. But, I can't locate any way to get this information from VFP at run-time, without having the child class explicitly define a collection of method names or something to that regard (which is exactly what I'm hoping to avoid).
Here's is a basic stub:
define class UnitTest as custom && would be abstract if VFP supported that
procedure MainMethod()
&& run all methods that begin with test_
endproc
enddefine
define class AUnitTest as UnitTest
procedure test_thingA()
...
endproc
procedure test_thingB()
...
endproc
enddefine
Would love anyone's ideas on how to get at the child methods from the parent. (Also open to a better implementation idea, if I'm going about this wrong, I think the basic idea of what I'm going for is clear).
Thanks so much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AMEMBERS() 函数可用于获取方法列表。
The AMEMBERS() function could be used to get a list of methods.