Proposal: user defined attributes

Manu turkeyman at gmail.com
Sat Mar 17 14:55:27 PDT 2012


On 17 March 2012 23:52, Manu <turkeyman at gmail.com> wrote:

> On 17 March 2012 21:56, Walter Bright <newshound2 at digitalmars.com> wrote:
>
>> On 3/16/2012 7:11 AM, Manu wrote:
>>
>>> attribute myAttribute
>>> {
>>>   this(int something);
>>>
>>>   bool bNeedsAttention;
>>>
>>>   property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; }
>>> }
>>>
>>> @myAttribute(10) int thing;
>>>
>>> thing.refresh = true;
>>>
>>
>> Under the hood, where would that per-instance data be stored?
>>
>> Compile-time annotations can be stored internally to the compiler, but
>> per-instance runtime data? How is it connected to the instance? When is it
>> constructed and destroyed?
>>
>
> In Java+C# it just lives in the class somewhere. Put it right beside the
> attributed member, or maybe separate them into an attribute section at the
> end of the class (to preserve structural layout). Construct along with the
> class, I suppose the moment would be after member initialisation, but
> before the constructor executes.
> I wonder if it should only be allowed on classes/class members... adding
> hidden data to a 'struct' almost defeats the purpose. Java doesn't have
> 'struct', so no problem. I wonder what C# does exactly...
>

I tend to think of 'struct's as 'passive', and compile-time annotations
would provide me with every use case I can imagine for my own purposes in
the case of structs. classes seem far more likely to need stateful
attributes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120317/43228dff/attachment.html>


More information about the Digitalmars-d mailing list