Skip to content

Instantly share code, notes, and snippets.

@Laeeth
Created January 11, 2015 00:24
Show Gist options
  • Save Laeeth/e5a772175d6fa6daba1a to your computer and use it in GitHub Desktop.
Save Laeeth/e5a772175d6fa6daba1a to your computer and use it in GitHub Desktop.
reflection
module deneme;
import std.string;
import std.traits;
struct MyAttr
{}
@MyAttr
void foo(int i, double d) pure @nogc nothrow @property
{}
void main()
{
foreach (m; __traits(allMembers, deneme)) {
pragma(msg, format("module member: %s", m));
static if (mixin ("isCallable!" ~ m)) {
pragma(msg, format("%s is callable", m));
foreach (funcAttr;
mixin (format("__traits(getFunctionAttributes,
%s)", m))) {
pragma(msg, format(" function attribute: %s", funcAttr));
}
foreach (attr; mixin (format("__traits(getAttributes, %s)",
m))) {
static if (is (attr == MyAttr)) {
pragma(msg, format(" uda: %s", attr.stringof));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment