Custom attributes C#

Daniel Keep daniel.keep.lists at gmail.com
Thu Sep 27 10:59:41 PDT 2007



Janice Caron wrote:
> On 9/27/07, Bruno Medeiros <brunodomedeiros+spam at com.gmail> wrote:
>> It's a concept similar to Java's annotations, aren't you familiar with
>> those either?
> 
> Nope. I have always found C and C++ (and now D) to be perfectly
> adequate for every need I've ever had.
> 
> So tell me, what are these things _for_? What's the _point_ of them?
> What do they do, and why would adding them to D be a good idea.
> 
> What will it enable me to do that I can't already do in C, C++ or D?

Look, ignore the syntax; it's not important.  Pretend I used @s or $s or
whatever makes you comfortable.

The point is, it's a system for annotating declarations.  Like how you
scribble in the margins of a book next to a particularly inane
paragraph: "this guy is nuts!"  You know... *metadata*.

And I would have thought the examples I gave before were a pretty good
example of why they're useful.  Look at the first class; I've used them
to annote fields with information on how they should be serialised.  In
the second one I've used them to indicate how an object might be bound
to a UI.

Ary has an even better example: specifying how to bind an object to a
database table.  That's like what ActiveRecord (the real magic behind
Ruby on Rails) does.  It'd practically give us half of D on Rails.  :P

The point is to give programmers a way of adding extra information about
a declaration that you wouldn't normally be able to convey.

Granted, you *could* do this in D right now; in much the same way you
can do OO programming in assembler.  You could probably fake it with
variadic templates and structs, etc., but it'd be ugly as heck.

	-- Daniel



More information about the Digitalmars-d mailing list