In the previous two recipes, we got a list of functions, including overloads and signatures in the form of types. To do really interesting things with function reflection, we need to dig into the details, isolating the return type and function parameters.
Let's execute the following steps to determine names, types, and default values of function parameters:
Import
std.traits
. The Phobos module makes the task easier and is much more readable than the direct implementation.Get the function symbol. You may use the name directly (do not take the address of it, as we want to work on the function itself, and not on the pointer) by using
__traits(getMember)
or__traits(getOverloads)
.Isolate the return value with
ReturnType!func
. You may use this in any context in which you will use a type.Get the parameter types with
ParameterTypeTuple!func
. You may declare a variable with this type and fill arguments with it.Get the...