Get derived classes
Get derived classes
You can get directly derived classes by using the GetSubClasses
method of the IClass
object.
public void GetSubClasses(ICommandContext c, ICommandParams p)
{
//Get metamodels
IMetamodels metamodels = c.App.Workspace.CurrentProject.Profile.Metamodels;
//Get the class of "EntityBase"
IClass cls = metamodels.GetClass("EntityBase");
//Print the class name
c.App.Output.WriteLine("sample", $"Class: {cls.DisplayName}");
//Get derived classes
IClassCollection subClasses = cls.GetSubClasses();
foreach (var subClass in subClasses)
{
//Print the class name
c.App.Output.WriteLine("sample", $"SubClass: {subClass.DisplayName}");
}
}
Get all derived classes
You can get all derived classes, including the derived classes of derived classes, by using the GetAllSubClasses
method of the IClass
object.
public void GetAllSubClasses(ICommandContext c, ICommandParams p)
{
//Get metamodels
IMetamodels metamodels = c.App.Workspace.CurrentProject.Profile.Metamodels;
//Get the root model base class
IClass cls = metamodels.GetClass("RootModelBase");
//Print the class name
c.App.Output.WriteLine("sample", $"Class: {cls.DisplayName}");
//Get all derived classes
IClassCollection subClasses = cls.GetAllSubClasses();
foreach (var subClass in subClasses)
{
//Print the class name
c.App.Output.WriteLine("sample", $"SuperClass: {subClass.DisplayName}");
}
}