digitalmars.D.bugs - [Issue 15427] New: dynamic casting functions should be available in
- via Digitalmars-d-bugs (28/28) Dec 08 2015 https://issues.dlang.org/show_bug.cgi?id=15427
https://issues.dlang.org/show_bug.cgi?id=15427 Issue ID: 15427 Summary: dynamic casting functions should be available in TypeInfo_Class Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: ketmar ketmar.no-ip.org it's sometimes useful to emulate dynamic casting in runtime having only TypeInfo_Class at hands. now one has to rely on undocumented (and unexported) `_d_dynamic_cast()` and friends, writing something like this: // get druntime cast function private extern(C) void* _d_dynamic_cast (Object o, ClassInfo c); bool isCastable (Object O, TypeInfo_Class ti) { return (_d_dynamic_cast(o, ti) !is null); } it would be fine to introduce and use a documented API for that, like this: ti.dynamicCast(O) ti.isBaseOf(O) i.e. we should add these methods to TypeInfo_Class. also, the same methods should be added to TypeInfo_Interface. --
Dec 08 2015