User Defined Attributes

Jacob Carlborg doob at me.com
Wed Nov 14 04:33:57 PST 2012


On 2012-11-14 12:18, Tove wrote:
> On Wednesday, 14 November 2012 at 11:08:04 UTC, Leandro Lucarella wrote:
>>
>> Can you provide one concrete case where it makes sense NOT to restrict
>> UDAs to
>> types and it's different from restricting exception to classes derived
>> from
>> Exception?
>>
>> Thank you.
>
> There was the example with Thrift...
>
>    struct UserProfile {
>          1: i32 uid,
>          2: string name,
>          3: string blurb
>        }
>        service UserStorage {
>          void store(1: UserProfile user),
>          UserProfile retrieve(1: i32 uid)
>        }
>
> You could use a user defined type for the struct... but for the members
> it would make sense to use the native type directly... and if you
> traverse the annotation in sequence rather than as standalone entities..
> it's perfectly safe to use 1,2,3 as annotation...
>
> i.e. first scan for the Thrift symbol, then scan for native typed int:s...

I assume you mean something like:

struct UserProfile {
     [1] i32 uid;
     [2] string name;
     [3] string blurb;
}

In that case I would much rather prefer this:

struct UserProfile {
     @Id(1) i32 uid;
     @Id(2) string name;
     @Id(3) string blurb;
}

Where Id is "thrift.attributes.Id" or something similar.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-announce mailing list