Jump to page: 1 24  
Page
Thread overview
Getters/setters generator
Dec 09, 2016
Eugene Wissner
Dec 09, 2016
Iakh
Dec 09, 2016
Eugene Wissner
Dec 10, 2016
Iakh
Dec 11, 2016
Eugene Wissner
Dec 09, 2016
Iakh
Jan 17, 2017
Eugene Wissner
Jan 17, 2017
Stefan Koch
Jan 17, 2017
Eugene Wissner
Jan 17, 2017
Mark
Jan 18, 2017
Mark
Jan 18, 2017
Nemanja Boric
Jan 19, 2017
Mark
Dec 10, 2016
Stefan Koch
Dec 10, 2016
Mike Bierlee
Dec 11, 2016
Mike Parker
Dec 11, 2016
Mike Bierlee
Dec 11, 2016
Mike Parker
Dec 13, 2016
Kapps
Dec 11, 2016
Eugene Wissner
Dec 14, 2016
Eugene Wissner
Jun 13, 2017
jmh530
Jun 13, 2017
Eugene Wissner
Jun 13, 2017
jmh530
Jun 13, 2017
jmh530
Jun 15, 2017
Eugene Wissner
Jan 17, 2017
Eugene Wissner
December 09, 2016
Hello,

we've just open sourced a small module ("accessors") that helps to generate getters and setters automatically:
https://github.com/funkwerk/accessors
http://code.dlang.org/packages/accessors

It takes advantage of the UDAs and mixins. A simple example would be:

import accessors;

class WithAccessors
{
    @Read @Write
    private int num_;

    mixin(GenerateFieldAccessors);
}

It would generate 2 methods "num": one to set num_ and one to get its value. Of cause you can generate only @Read without @Write and vice versa. There are some more features, you can find the full documentation in the README.
"GenerateFieldAccessors" mixin should be added into each class/struct that wants to use auto generated accessors.
December 09, 2016
On Friday, 9 December 2016 at 10:27:05 UTC, Eugene Wissner wrote:
> Hello,
>
> we've just open sourced a small module ("accessors") that helps to generate getters and setters automatically:
> https://github.com/funkwerk/accessors
> http://code.dlang.org/packages/accessors
>
> It takes advantage of the UDAs and mixins. A simple example would be:
>
> import accessors;
>
> class WithAccessors
> {
>     @Read @Write
>     private int num_;
>
>     mixin(GenerateFieldAccessors);
> }
>
> It would generate 2 methods "num": one to set num_ and one to get its value. Of cause you can generate only @Read without @Write and vice versa. There are some more features, you can find the full documentation in the README.
> "GenerateFieldAccessors" mixin should be added into each class/struct that wants to use auto generated accessors.

Is there possibility to remove affixes in generated accessor names?
December 09, 2016
mixin template GenerateFieldAccessorMethods()
{
    static enum GenerateFieldAccessorMethods()
    {
        string result = "";
        return result;
    }
}

Strange syntax
December 09, 2016
On Friday, 9 December 2016 at 12:37:58 UTC, Iakh wrote:
>
> Is there possibility to remove affixes in generated accessor names?

No, there is no way to manipulate the accessor names. What affixes do you mean?
December 09, 2016
On 12/9/16 5:27 AM, Eugene Wissner wrote:
> Hello,
>
> we've just open sourced a small module ("accessors") that helps to
> generate getters and setters automatically:
> https://github.com/funkwerk/accessors
> http://code.dlang.org/packages/accessors
>
> It takes advantage of the UDAs and mixins. A simple example would be:
>
> import accessors;
>
> class WithAccessors
> {
>     @Read @Write
>     private int num_;
>
>     mixin(GenerateFieldAccessors);
> }
>
> It would generate 2 methods "num": one to set num_ and one to get its
> value. Of cause you can generate only @Read without @Write and vice
> versa. There are some more features, you can find the full documentation
> in the README.
> "GenerateFieldAccessors" mixin should be added into each class/struct
> that wants to use auto generated accessors.

Love it, and was toying with similar ideas too. One good extension is to add a predicate to the setter, which guards the assignment. -- Andrei
December 10, 2016
On Friday, 9 December 2016 at 10:27:05 UTC, Eugene Wissner wrote:
> Hello,
>
> we've just open sourced a small module ("accessors") that helps to generate getters and setters automatically:
> https://github.com/funkwerk/accessors
> http://code.dlang.org/packages/accessors
>
> It takes advantage of the UDAs and mixins. A simple example would be:
>
> import accessors;
>
> class WithAccessors
> {
>     @Read @Write
>     private int num_;
>
>     mixin(GenerateFieldAccessors);
> }
>
> It would generate 2 methods "num": one to set num_ and one to get its value. Of cause you can generate only @Read without @Write and vice versa. There are some more features, you can find the full documentation in the README.
> "GenerateFieldAccessors" mixin should be added into each class/struct that wants to use auto generated accessors.

Oh my this is going to be a compiletime hog if used excessively.
Due the use of fqn.

December 10, 2016
On Friday, 9 December 2016 at 16:30:55 UTC, Eugene Wissner wrote:
> On Friday, 9 December 2016 at 12:37:58 UTC, Iakh wrote:
>>
>> Is there possibility to remove affixes in generated accessor names?
>
> No, there is no way to manipulate the accessor names. What affixes do you mean?

You can remove suffix "_" so "name_" becomes "name". But I like
to see genarated accessors "name" for field "m_name"
December 10, 2016
On Friday, 9 December 2016 at 10:27:05 UTC, Eugene Wissner wrote:
> It would generate 2 methods "num": one to set num_ and one to get its value.

It would be great if you could generate @properties instead. I like the more natural way of accessing those instead of getters/setters.
December 11, 2016
On Saturday, 10 December 2016 at 20:25:05 UTC, Mike Bierlee wrote:
> On Friday, 9 December 2016 at 10:27:05 UTC, Eugene Wissner wrote:
>> It would generate 2 methods "num": one to set num_ and one to get its value.
>
> It would be great if you could generate @properties instead. I like the more natural way of accessing those instead of getters/setters.

What are properties if not "getters" and "setters"? From the original post: "It would generate 2 methods "num": one to set num_ and one to get its value."

Two methods named "num". No "get" or "set" in sight.
December 11, 2016
On Sunday, 11 December 2016 at 02:17:18 UTC, Mike Parker wrote:
> On Saturday, 10 December 2016 at 20:25:05 UTC, Mike Bierlee wrote:
>> On Friday, 9 December 2016 at 10:27:05 UTC, Eugene Wissner wrote:
>>> It would generate 2 methods "num": one to set num_ and one to get its value.
>>
>> It would be great if you could generate @properties instead. I like the more natural way of accessing those instead of getters/setters.
>
> What are properties if not "getters" and "setters"? From the original post: "It would generate 2 methods "num": one to set num_ and one to get its value."
>
> Two methods named "num". No "get" or "set" in sight.

I was under the impression that you could only access methods as if they were fields using the @property attribute. After carefully reading the documentation I see this is not the case (UFCS does this). Still there are some added benefits from using @property to completely threat them as fields. It would be nice if you could add @property to the generated getters/setters.
« First   ‹ Prev
1 2 3 4