@@ -1102,6 +1102,61 @@ class TypeInfo_Class : TypeInfo
1102
1102
}
1103
1103
return o;
1104
1104
}
1105
+
1106
+ /**
1107
+ * Returns true if the class described by this TypeInfo_Class derives from
1108
+ * the interface described by `parent`.
1109
+ *
1110
+ * Params:
1111
+ * parent = TypeInfo for some interface
1112
+ * Returns:
1113
+ * true if the class described by this TypeInfo_Class derives from the
1114
+ * interface described by `parent`, false otherwise.
1115
+ */
1116
+ bool isDerivedFrom (scope const TypeInfo_Interface parent) const @nogc nothrow pure @safe
1117
+ {
1118
+ return parent ! is null && interfaceConvertibleFrom(parent.info, this );
1119
+ }
1120
+
1121
+ /**
1122
+ * Returns true if the class described by this TypeInfo_Class derives from
1123
+ * the class described by `parent`.
1124
+ *
1125
+ * Params:
1126
+ * parent = TypeInfo for some class
1127
+ * Returns:
1128
+ * true if the class described by this TypeInfo_Class derives from the
1129
+ * class described by `parent`, false otherwise.
1130
+ */
1131
+ bool isDerivedFrom (scope const TypeInfo_Class parent) const @nogc nothrow pure @safe
1132
+ {
1133
+ if (parent is null )
1134
+ return false ;
1135
+ if (parent is this || parent.name == this .name)
1136
+ return true ;
1137
+ return this .base ! is null && this .base.isDerivedFrom(parent);
1138
+ }
1139
+
1140
+ /*
1141
+ * Params:
1142
+ * interfaceInfo = the classinfo of the maybe-parent interface
1143
+ * ti = the classinfo of the maybe-child interface
1144
+ * Returns:
1145
+ * true if `ti` is derived from `interfaceInfo`, false otherwise
1146
+ */
1147
+ private static bool interfaceConvertibleFrom (scope const TypeInfo_Class interfaceInfo,
1148
+ scope const TypeInfo_Class ti) @nogc nothrow pure @safe
1149
+ {
1150
+ if (interfaceInfo is ti || interfaceInfo.name == ti.name)
1151
+ return true ;
1152
+ foreach (interface_; ti.interfaces)
1153
+ if (interface_.classinfo is interfaceInfo || interface_.classinfo.name == interfaceInfo.name)
1154
+ return true ;
1155
+ foreach (interface_; ti.interfaces)
1156
+ if (interfaceConvertibleFrom(interfaceInfo, interface_.classinfo))
1157
+ return true ;
1158
+ return ti.base is null ? false : interfaceConvertibleFrom(interfaceInfo, ti.base);
1159
+ }
1105
1160
}
1106
1161
1107
1162
alias ClassInfo = TypeInfo_Class ;
@@ -1191,6 +1246,21 @@ class TypeInfo_Interface : TypeInfo
1191
1246
override @property uint flags() nothrow pure const { return 1 ; }
1192
1247
1193
1248
TypeInfo_Class info;
1249
+
1250
+ /**
1251
+ * Returns true if the interface described by this TypeInfo_Interface
1252
+ * derives from the interface described by `parent`.
1253
+ *
1254
+ * Params:
1255
+ * parent = TypeInfo for some interface
1256
+ * Returns:
1257
+ * true if the interface described by this TypeInfo_Interface derives from
1258
+ * the interface described by `parent`, false otherwise.
1259
+ */
1260
+ bool isDerivedFrom (scope const TypeInfo_Interface parent) const @nogc nothrow pure @safe
1261
+ {
1262
+ return parent ! is null && TypeInfo_Class .interfaceConvertibleFrom(parent.info, this .info);
1263
+ }
1194
1264
}
1195
1265
1196
1266
class TypeInfo_Struct : TypeInfo
0 commit comments