Does D have class' attributes like C#'s?

Anonymouse asdf at asdf.net
Sat Dec 16 20:05:15 UTC 2017


On Saturday, 16 December 2017 at 19:57:30 UTC, Marc wrote:
> C# has a quite nice way to store metadata about a property by a 
> feature called atributes[1]. For example, I can write something 
> like this:
>
>> class A {
>>    [TextSize(256)]
>>    string Name { get; set; }
>> }
>
> So using runtime/reflection I can retrieve the TextSize value 
> associated to A.name property.
>
> Does D have something similar?

UDAs? User Defined Attributes.

https://dlang.org/spec/attribute.html#UserDefinedAttribute
http://ddili.org/ders/d.en/uda.html

class A {
     @TextSize(256)
     string name() { /* ... */ }
}


More information about the Digitalmars-d-learn mailing list