Listing a class's methods trough mixin

半世苍凉 提交于 2019-12-23 12:24:13

问题


I want to list methods of a class in a mixin.

To do it I assume I have to open the file containing the source code in the mixin, but finding that file's name is harder than I thought.

I tried using

__FILE__

but it gives the mixin declaration's file... so I would have to define the mixin in every file... which doesn't make any sense since the goal is to reduce boilerplate code.

For now my solution is to pass the filename as an argument inside the class's constructor and call the mixin from there. Since I will do that in all class that inherit from the same parent class, I would ideally want to put it in the parent class's constructor and to register the child class's methods.

Is there a better way of doing this? Anything that could search the class for methods without having to open the file?


回答1:


This should be a good place to start: http://dlang.org/traits.html#allMembers

Then you can use the other traits to figure which members are methods.



来源:https://stackoverflow.com/questions/11314596/listing-a-classs-methods-trough-mixin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!