, :
import std.stdio;
class Math {
static string noArgs(string[] s) { writeln(s); return ""; }
static string withOneArg(string[] s) { writeln(s); return ""; }
static string withTwoArgs(string[] s) { writeln(s); return ""; }
}
class String {
static string oneArg(string[] s) { return null; }
}
string execute(string what, string[] params) {
import std.string;
auto parts = what.split(".");
auto className = parts[0];
auto methodName = parts[1];
import std.typetuple;
switch(className) {
default: assert(0, "unknown class");
foreach(possibleClass; TypeTuple!(Math, String)) {
case possibleClass.stringof:
switch(methodName) {
default: assert(0, "unknown method");
foreach(memberName; __traits(derivedMembers, possibleClass)) {
case memberName:
return __traits(getMember, possibleClass, memberName)(params);
break;
}
}
break;
}
}
assert(0);
}
void main() {
execute("Math.withOneArg", ["cool"]);
execute("String.oneArg", ["cool"]);
}
, mixin, . , , TypeTuple , . mixin, , ; possibleClasses execute , , undefined , .
mixin, , , . , D: foreach (.. foreach , TypeTuple, , __traits...), case!
, , , switch , , foreach , , , case that_loop_var: , .
, __traits(getMember) mixin . , IMO - . , ( __traits(getOverloads) __traits(getMember), ).
, switch es case. switch , break label_name_here;, , . continue .
, -, string[] , std.traits. , , - , std.traits.ParameterTypeTuple ReturnType , , .