On 2013-09-20 08:59, ilya-stromberg wrote:
Can I explicitly specify when I can use attribute? Something like
this:
@attribute("field")
struct matches(string mustMatch)
{
}
string wrongAttribute
{
}
class Foo
{
@matches("[0-9]+")
string someNumber; //OK, it's a field
}
@matches("[0-9]+") //Error, it's a class, not a field
class Bar
{
}
@wrongAttribute //Error, this attribute doesn't exist
class C
{
}
Unfortunately you can't. I tag all my structs which are supposed to be
used as UDA's with a @attribute UDA.
struct attribute {}
@attribute struct matches(string mustMatch) {}
Then I have some wrappers around __traits(getAttributes) that will, by
default, only return UDA's that them self have the @attribute UDA
attached to them.
https://github.com/jacob-carlborg/orange/blob/master/orange/core/Attribute.d
--
/Jacob Carlborg