On 2012-03-09 11:56, Manu wrote:
Does D have a nice way to add annotations or custom attributes to entities?
Unfortunately no.
In Java/C# for example, it is common to annotate things with useful compile time information. I'd like to be able to do that in D on occasion. For instance, I'm serialising some struct/class using reflection to some text format, but there are a couple of members in a particular class that I don't want to be written. A nice solution might be that I could annotate various members: @DoNotSerialise int thing; ... or something along those lines, whatever concept you want to apply, which I could then inspect in static if() logic to produce some requested additional behaviour. This is a trivial example, but looking at C#/Java, you can see how many useful things can be done with this sort of system. How would it be done currently?
Yeah, it would be so nice to have. As a workaround you can mixin some code, variables or similar in a class/struct.
For serialization you could use my library Orange, which already supports this.
You can have a look at the NonSerialized template at: http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializable.html https://github.com/jacob-carlborg/orange -- /Jacob Carlborg