www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Named UDA's

reply "JS" <js.mdnq gmail.com> writes:
I guess D doesn't support named UDA's directly?

e.g.,

 (Name = "My Name", Other = .34)

It would be nice to have the ability to have an "attribute" 
hierarchy where looking up attributes on objects could easily be 
done.

e.g.,

 (Name = "s", Other = 2) struct s
{
      (Name = "q", Default_Value = 4) int q = 4;
}

which would form a hierarchy

Attributes[]...[]

Which  [s].Attributes = {"Name" = "s", "Other" = 2} (Key/Value 
pairs)

 [s][q].Attributes = {"Name" = "q", "Other" = 2, "Default_Value" 
= 4 }

(attributes are inherited

Querying at runtime would be a binary search or O(1) if the 
object type is known.

Anyways, Just an idea I had when trying to make attributes more 
useful.
Aug 01 2013
parent "Dicebot" <public dicebot.lv> writes:
On Thursday, 1 August 2013 at 11:02:00 UTC, JS wrote:
 Anyways, Just an idea I had when trying to make attributes more 
 useful.
struct Name { string data; } Name("hello") void foo(); I favor this approach much more because of strong typing.
Aug 01 2013