User defined safety?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Aug 30 10:54:29 PDT 2011


On 8/30/11 12:41 PM, jdrewsen wrote:
> Couldn't this be used for marking classes as serializable. Something
> like this:
>
> class Foo {
>
> @custom("serialize") Cake theCake;
> Bar cache;
> }
>
> SerializeCustom!("serialize", Foo);
>
> template SerializeCustom(string attribute, alias cls) {
> foreach (m; __traits(listMembers, cls)) {
> static if ( __traits(hasCustomAttribute(attribute, m) ) {
> Serializer.register(cls, m);
> }
>
> }
> }
>
> ----------
>
> Though I would prefer if you could just write:
> @custom("serialize") class Foo { ... }
>
> instead of:
> SerializeCustom!("serialize", Foo);

I think a convention based on the name of the field shouldn't be half bad.

Andrei


More information about the Digitalmars-d mailing list