Custom attributes (again)
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Apr 6 07:37:19 PDT 2012
On 4/6/12 1:47 AM, Walter Bright wrote:
> On 4/5/2012 5:00 AM, Manu wrote:
> > C# and Java both have attributes, following these established design
> patterns, I
> > don't think there should be any mystery over how they should be
> implemented.
>
> I was thinking of something along the lines of what has been proposed
> here earlier:
>
> @attr(identifier = expression)
>
> as a storage class, like:
>
> @attr(foo = bar + 1) int x;
>
> and then:
>
> __traits(hasAttribute, x, foo)
>
> would return true, and:
>
> __traits(getAttribute, x, foo)
>
> would return the expression (bar+1). The expression would be
> compile-time only, evaluated at the point of declaration.
You also need means to enumerate attributes.
Andrei
More information about the Digitalmars-d
mailing list