Custom attributes (again)

Jacob Carlborg doob at me.com
Fri Apr 6 06:08:31 PDT 2012


On 2012-04-06 14:38, Piotr Szturmaj wrote:

> Do you mean return type? I think your syntax has some serious
> disadvantages. Consider parameters and multiple attributes.
>
> For return types I'd like to see something like this:
>
> @return: not_null
> @return: MyAttr("foo")
> Foo bar(@custom int a) {}
>
> This is similar to C#'s [return: MyAttr]. Alternatively it might be:
>
> @return(not_null)
> @return(MyAttr("foo"))

Hmm, or something like how Java does it. You attached this information 
when you declare the attribute:

@Retention(RetentionPolicy.RUNTIME) // Make this annotation accessible 
at runtime via reflection.
  @Target({ElementType.METHOD})  // This annotation can only be applied 
to class methods.

public @interface Tweezable {
}

Or with another syntax:

@attribute @target(type) struct not_null {}

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list