Get the inherited class
Get the directly inherited class
You can get the directly inherited class by using the SuperClasses property of the IClass object.
public void GetSuperClasses(ICommandContext c, ICommandParams p)
{
//Get metamodels
IMetamodels metamodels = c.App.Workspace.CurrentProject.Profile.Metamodels;
//Get the class of "Actor"
IClass cls = metamodels.GetClass("Actor");
//Print the class name
c.App.Output.WriteLine("sample", $"Class: {cls.DisplayName}");
//Get the inherited class
IClassCollection superClasses = cls.SuperClasses;
foreach (var superClass in superClasses)
{
//Print the class name
c.App.Output.WriteLine("sample", $"SuperClass: {superClass.DisplayName}");
}
}
Get all inherited classes
You can get all inherited classes, including the inheritors of the inherited class, by using the GetAllSuperClasses method of the IClass object.
public void GetAllSuperClasses(ICommandContext c, ICommandParams p)
{
//Get metamodels
IMetamodels metamodels = c.App.Workspace.CurrentProject.Profile.Metamodels;
//Get the class of "Actor"
IClass cls = metamodels.GetClass("Actor");
//Print the class name
c.App.Output.WriteLine("sample", $"Class: {cls.DisplayName}");
//Get all inherited classes
IClassCollection superClasses = cls.GetAllSuperClasses();
foreach (var superClass in superClasses)
{
//Print the class name
c.App.Output.WriteLine("sample", $"SuperClass: {superClass.DisplayName}");
}
}