Skip to content

Instantly share code, notes, and snippets.

@zakky-dev
Created September 9, 2013 15:44
Show Gist options
  • Save zakky-dev/6497452 to your computer and use it in GitHub Desktop.
Save zakky-dev/6497452 to your computer and use it in GitHub Desktop.
D言語で指定したクラスのメソッド名を文字列で全て取得するサンプル
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