Custom attributes (again)

Jacob Carlborg doob at me.com
Fri Apr 6 05:23:59 PDT 2012


On 2012-04-06 05:30, Ary Manzana wrote:

> I don't understand the difference between "storage class" and "type
> constructor". I guess I do. But my answer is the same as deadalnix: they
> are attached to declarations (at compile time).
>
> Can you give us an example of the confusion that arose? I can't
> understand it without examples.
>
> I think it should work like this:
>
> @custom
> class Foo {
>
> @ custom
> void bar() { }
>
> void baz() { }
> }
>
> class Other {}
>
> __traits(hasAttribute, Foo, 'custom') --> true
> __traits(hasAttribute, Other, 'custom') --> false
>
> // I have no idea how to iterate the members of Foo, or get a reference
> to the "bar" method... I can't understand what __traits(getMember)
> returns from the docs...

I would like to have the possibility to attach attributes to types and 
parameters as well. Some think like this:

class Bar
{
     @not_null(Foo) bar (@custom int a) {}
}

Where @not_null is attached to "Foo" and @custom is attached to "a".

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list