Created
September 9, 2013 15:44
-
-
Save zakky-dev/6497452 to your computer and use it in GitHub Desktop.
D言語で指定したクラスのメソッド名を文字列で全て取得するサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Class(T) { | |
private bool[string] methods; | |
this() { | |
initialize(); | |
} | |
void initialize() { | |
foreach(member; __traits(derivedMembers, T)) { | |
if(__traits(isVirtualFunction, mixin("T." ~ member))) { | |
this.methods[member] = true; | |
} | |
} | |
} | |
string[] getMethods() { | |
return this.methods.keys; | |
} | |
} | |
void main() { | |
class Base { | |
abstract void overrideMethod(); | |
abstract void finalOverrideMethod(); | |
} | |
class Test : Base { | |
protected int member; | |
void publicMethod() {} | |
final void finalMethod() {} | |
override void overrideMethod() {} | |
final override void finalOverrideMethod() {} | |
} | |
import std.stdio; | |
auto cls = new Class!Test; | |
cls.getMethods.writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment