How do I generate `setX` methods for all private mutable variables in a class?

Ki Rill rill.ki at yahoo.com
Mon Jun 5 13:57:20 UTC 2023


How do I generate `setX` methods for all private mutable 
variables in my class? Do I need to use `__traits`?

I need this for my [tiny-svg](https://github.com/rillki/tiny-svg) 
project to generate `setX` methods for all Shapes.

Example:
```D
class Rectangle {
     private immutable ...;
     private Color fillColor;
     private Color strokeColor;
     private uint strokeWidth;

     this(int x, int y) {...}

     mixin(???);

     // I need this:
     Rectangle setFillColor(Color color) {...}
     Rectangle setStrokeColor(Color color) {...}
     Rectangle setStrokeWidth(uint color) {...}
}
```

Usage:
```D
new Rectangle(10, 10)
     .setFillColor(Colors.white)
     .setStrokeColor(Colors.black)
     .setStrokeWidth(3);
```


More information about the Digitalmars-d-learn mailing list