C# System.Type and Java java.lang.Class have `isAssignableFrom` to conveniently determine at runtime whether a class inherits from or implements another class or interface. Adding something similar to TypeInfo_Class and TypeInfo_Interface would be useful. The name "isAssignableFrom" would be familiar to people coming from C# or Java but is potentially misleading since since -- due to "alias this" and the ability to overload opAssign -- whether a value of type Y can be assigned to a variable of type X is not the same as asking if Y inherits from or implements X. The language "derives from" is used in the D specification so I'm suggesting "isDerivedFrom" swapping the receiver and argument relative to "isAssignableFrom."
@n8sh created dlang/druntime pull request #2770 "Give TypeInfo_Class/TypeInfo_Interface.isDerivedFrom like C#/Java isAssignableFrom" fixing this issue: - Fix Issue 20178 - Add TypeInfo_Class/TypeInfo_Interface.isDerivedFrom Equivalent to C#/Java isAssignableFrom with the argument swapped with the receiver. Naming the method "isAssignableFrom" would be more familiar to people coming from C#/Java but is potentially misleading: "alias this" and overloadable opAssign mean that this would not actually indicate whether values of one type could be assigned to another. https://github.com/dlang/druntime/pull/2770
dlang/druntime pull request #2770 "Give TypeInfo_Class/TypeInfo_Interface.isBaseOf like C#/Java isAssignableFrom" was merged into master: - bc10972b8e5d6c70a9fce3abcc598f6cf120f08d by Nathan Sashihara: Fix Issue 20178 - Add TypeInfo_Class/TypeInfo_Interface.isBaseOf Equivalent to C#/Java isAssignableFrom. Naming the method "isAssignableFrom" would be more familiar to people coming from C#/Java but is potentially misleading: "alias this" and overloadable opAssign mean that this would not actually indicate whether values of one type could be assigned to another. Adding qualifiers to rt.cast_ functions. https://github.com/dlang/druntime/pull/2770