User defined attributes use

Jacob Carlborg doob at me.com
Sun Sep 15 11:00:11 PDT 2013


On 2013-09-15 19:34, matovitch wrote:
> Hi everyone,
>
> I read the documentation about user defined attributes, but I don't see
> their uses.

I'm using it in my serialization library:

struct Foo
{
     int a;
     @nonSerialized int b;
}

Indicates "b" will not be serialized.

struct Bar
{
     int a;

     @onSerializing void foo ()
     {
         // called when "Bar" is being serialized
     }
}

"foo" will be called when "Bar" is being serialized

For another project I'm using it as part of a testing framework:

@describe("Lexer")
{
     @context("valid string literal")
     {
         @it("should return a token with the type 
TokenKind.stringLiteral") unittest
         {
             auto code = `"asd"`;
             auto lexer = new Lexer(code);

             assert(lexer.scan.kind == TokenKind.stringLiteral);
         }
     }
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list