Custom attributes C#

David Wilson dw at botanicus.net
Thu Sep 27 11:31:36 PDT 2007


On 27/09/2007, Daniel Keep <daniel.keep.lists at gmail.com> wrote:

> The point is, it's a system for annotating declarations.

Modules, fields, properties, methods, structs, classes, parameters and
return types to be precise (IIRC).

> And I would have thought the examples I gave before were a pretty good
> example of why they're useful.

Source code can only ever show the *how* ;).


.NET attributes are a fairly awesome concept, but I'm not sure if they
fit in with the simplicity of D. Another thing is, .NET has a rather
powerful and well designed API for doing introspection, whereas D's
capabilities are quite simplistic.

I think it's a nice idea, and indeed I was looking for something
similar in D not a week ago. ;)  But I wouldn't miss the complexity if
it were never added. Attributes are a luxurious way of doing things
rather than a necessity.


David.


>  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