[Issue 15427] dynamic casting functions should be available in TypeInfo_Class
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Dec 9 00:01:13 PST 2015
https://issues.dlang.org/show_bug.cgi?id=15427
--- Comment #2 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
sample patch:
diff --git a/src/object.d b/src/object.d
index 097fc5a..6eb9163 100644
--- a/src/object.d
+++ b/src/object.d
@@ -21,6 +21,8 @@ private
{
extern (C) Object _d_newclass(const TypeInfo_Class ci);
extern (C) void rt_finalize(void *data, bool det=true);
+ extern (C) void* _d_dynamic_cast(Object o, ClassInfo c);
+ extern (C) int _d_isbaseof(ClassInfo oc, ClassInfo c);
}
// NOTE: For some reason, this declaration method doesn't work
@@ -860,6 +862,17 @@ unittest
*/
class TypeInfo_Class : TypeInfo
{
+ final void* dynamicCast (Object o)
+ {
+ return (o !is null ? _d_dynamic_cast(o, this) : null);
+ }
+
+ // is this typeinfo base of `o`?
+ final bool baseOf (Object o)
+ {
+ return (o !is null ? (_d_isbaseof(typeid(o), this) != 0) : false);
+ }
+
override string toString() const { return info.name; }
override bool opEquals(Object o)
--
More information about the Digitalmars-d-bugs
mailing list