Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
33
Task/Reflection-List-methods/D/reflection-list-methods.d
Normal file
33
Task/Reflection-List-methods/D/reflection-list-methods.d
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
struct S {
|
||||
bool b;
|
||||
|
||||
void foo() {}
|
||||
private void bar() {}
|
||||
}
|
||||
|
||||
class C {
|
||||
bool b;
|
||||
|
||||
void foo() {}
|
||||
private void bar() {}
|
||||
}
|
||||
|
||||
void printMethods(T)() if (is(T == class) || is(T == struct)) {
|
||||
import std.stdio;
|
||||
import std.traits;
|
||||
|
||||
writeln("Methods of ", T.stringof, ":");
|
||||
foreach (m; __traits(allMembers, T)) {
|
||||
static if (__traits(compiles, (typeof(__traits(getMember, T, m))))) {
|
||||
alias typeof(__traits(getMember, T, m)) ti;
|
||||
static if (isFunction!ti) {
|
||||
writeln(" ", m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
printMethods!S;
|
||||
printMethods!C;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue