yes:
public string foo;
Trivial property accessors are a waste of time IMO. Ruby forces you to do them but D doesn't.
If you want them anyway, a mixin template can do the job:
mixin template attr_accessor(Type, string name) {
static string codeGenerationHelper() {
string code;
// the variable
code ~= "private Type _" ~ name ~ ";";
// the getter
code ~= "public @property Type " ~ name ~ "() { return _" ~ name ~ "; }";
// the setter
code ~= "public @property Type " ~ name ~ "(Type a) { return _" ~ name ~ " = a; }";
return code;
}
mixin(codeGenerationHelper());
}
// here's how to use it
class Foo {
mixin attr_accessor!(string, "foo");
}
void main() {
auto foo = new Foo();
foo.foo = "test";
}