getAttr method
Guillaume Chéreau
charlie137 at gmail.com
Fri Feb 1 01:09:05 PST 2008
Hello, I would like to suggest an feature to the language :
Every time we try to access a member of an object that has no such member, the compiler try to call a special method with the member name as a template parameter.
This would be similar to the __getattr__ method in python, and it can be useful sometime.
Ex:
class Test {
string getAttr(string name)() {return name;}
}
void main() {
Test t = Test();
writefln(t.hello); // write "hello"
}
- Guillaume
More information about the Digitalmars-d
mailing list