Published on InterSystems Developer Community (https://community.intersystems.com)

Home > What's the fastest way to check if one class is a subclass of another

Question
Eduard Lebedyuk · Aug 31, 2017

What's the fastest way to check if one class is a subclass of another

I need to check if one class is a subclass of another (either direct or indirect).

For example:

Class Package.ClassA Extends %Library.Persistent
{
}

Class Package.ClassB Extends Package.ClassA 
{
}

Class Package.ClassC Extends Package.ClassB
{
}

In this example Package.ClassC is a subclass of 3 classes: %Library.Persistent, Package.ClassA, Package.ClassB.

So any of these checks should return 1:

Write ##class(Some.System.Class).IsSubclass("Package.ClassC", "%Library.Persistent")
Write ##class(Some.System.Class).IsSubclass("Package.ClassC", " Package.ClassA")
Write ##class(Some.System.Class).IsSubclass("Package.ClassC", " Package.ClassB")
#Beginner #Caché

Source URL:https://community.intersystems.com/post/whats-fastest-way-check-if-one-class-subclass-another