On 2011-01-20 14:47, Justin Johansson wrote:
Not long ago the Java Language people introduced the idea of annotations
together with an annotation processing tool (apt).

Now perhaps the idea of source code annotations is not actually a Java
invention per se, however for someone learning D is there any equivalent
idiom [of Java annotations] in the D language?

Depending on what you want to do you can create a template mixin that accepts string(s)/alias(es). For example: for the serialization library (http://dsource.org/projects/orange) I'm working on the following syntax is used:

class Foo
{
    int x;
    int y;
    int z;

    mixin NonSerialized!(z);
}

The above mixin indicates that the "z" instance variable shouldn't be serialized. This is (currently) achieved by defining a field in the mixed in template (which will be added to the class) which is a struct containing the string of the filed which shouldn't be serialized. Then I iterate over all the fields in the class with .tupleof and collects all mixed in fields in a list. Then I know what fields to skip later during the serialization.

--
/Jacob Carlborg

Reply via email to