Proposal: user defined attributes

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


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...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120317/d5753b1e/attachment.html>


More information about the Digitalmars-d mailing list