On Tuesday, 27 January 2015 at 08:19:46 UTC, Daniel Kozák wrote:
You can use this T:
class Parent {
@property string typeName(this T)() {
return T.stringof;
}
}
class Child : Parent {
}
void main() {
auto p = new Parent;
auto c = new Child;
assert(p.typeName == "Parent");
assert(c.typeName == "Child");
}
OTOH:
void main() {
auto p = new Parent;
auto c = new Child;
assert(p.typeName == "Parent");
assert(c.typeName == "Child");
p = c;
assert(p.typeName == "Parent");
}
It will still use the static type of the object that it's called
on, not the dynamic type.