traits compiles does not work for symbols from other modules
Andre Pany via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 24 14:40:23 PDT 2017
Hi,
I want to validate whether a class contains a specific attribute.
I have the attribute name as compile time string. This string
could either be a direct attribute of the class or a hierarchy
(TextSettings.Font.Size).
As example T is the class Label and p.name contains the text
"TextSettings.Font.Size".
TextSettings and Font are again classes.
mixin(`static if (__traits(compiles,
`~fullyQualifiedName!T~`.`~p.name~`)) {...}
__traits(compiles, ...) only works for symbols of the same
module, but not for symbols contained in other modules. I reduced
it to this example coding:
m1.d
-----------------
module m1;
import m2;
class Foo
{
int foo;
}
void main()
{
static assert(__traits(compiles, m1.Foo.foo));
static assert(__traits(compiles, m2.Bar.bar));
}
m2.d
---------------
module m2;
class Bar
{
int bar;
}
Why does the second assert throws? What can I use instead of
__traits(compiles,...) ?
Kind regards
André
More information about the Digitalmars-d-learn
mailing list