Proposal: user defined attributes

Jacob Carlborg doob at me.com
Mon Mar 19 14:23:54 PDT 2012


On 2012-03-19 21:44, Andrej Mitrovic wrote:

> When I implemented NonSerialized for Vladimir's json library he made a
> suggestion to simply create enums of each field that is not to be
> serialized and encode it as "fieldname_nonSerialized". That would
> enable using a NonSerialized mixin multiple times.
>
> I've yet to implement it in that way, I ran into some odd bugs but
> I'll have a look at this soon. My implementation used a hash lookup
> table for the fields, but using enums would make the code even
> simpler. Basically:
>
> struct Foo
> {
>      int x;
>      string name;
>      mixin(NonSerialized!name);
>      string lastName;
>      mixin(NonSerialized!lastName);
> }
>
> and this would expand to:
> struct Foo
> {
>      int x;
>      string name;
>      enum name_nonSerialized;
>      string lastName;
>      enum lastName_nonSerialized;
> }
>
> So all you'd have to do is use compile-time introspection and a little
> bit of string processing to figure out if a field should be serialized
> or not.

Yeah, but that will complicate the retrieval of the information.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list