Can attributes trigger functionality?

Psychological Cleanup via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 5 19:43:20 PDT 2017


I'm having to create a lot of boiler plate code that creates 
"events" and corresponding properties(getter and setter).

I'm curious if I can simplify this without a string mixin.

If I create my own attribute like

@Event double foo();

and I write any code that will trigger when the event is used and 
add more code(such as the setter property and events that I need?

Obviously I could write some master template that scans 
everything, but that seems to be far too much over kill. A string 
mixin is probably my only option but is a bit ulgy for me.

Since attributes can be defined by structures it seems natural 
that we could put functionality in them that are triggered when 
used but I'm unsure if D has such capabilities.

Thanks.







More information about the Digitalmars-d-learn mailing list