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")
?
Thank you, Alexander.
I've always used "%Extends" for this purpose:
Both methods scan the entire inheritance tree, but in the case of multiple inheritance, "%IsA" only finds primary superclasses, whereas "%Extends" finds all superclasses.
For example, consider the following class:
And the corresponding output:
More information about the difference between the two methods is discussed here.