On 2012-03-21 16:11, Andrei Alexandrescu wrote:
I think the liability here is that b needs to appear in two places, once
in the declaration proper and then in the NonSerialized part. (A
possible advantage is that sometimes it may be advantageous to keep all
symbols with a specific attribute in one place.) A possibility would be
to make the mixin expand to the field and the metadata at once.

Yes, but that just looks ugly:

class Foo
{
    int a;
    mixin NonSerialized!(int, "b");
}

That's why it's so nice with attributes.

Did you mean

static const __nonSerialized = ["b"];

?

Yes, sorry.

In case there are several non-serialized variables, how do you avoid
clashes between different definitions of __nonSerialized?

In my current implementation you are forced to only mixin one NonSerialized per type:

class Foo
{
    int a;
    int b;
    mixin NonSerialized!(a, b);
}

Of course there are ways around that with various pros and cons.

--
/Jacob Carlborg

Reply via email to