Skip to main content

Check the field type

You can get the field type name as a string by using the Type property of the IField object. If the field type is a user-defined class, you can get it with the IField.TypeClass property, and if it is an enumeration type, you can get it with the IField.TypeEnum property.

public void GetAllSuperClasses(ICommandContext c, ICommandParams p) 
{
//Get the 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}");

//Print the types of all fields
IFieldCollection fields = cls.GetFields();
foreach (var field in fields)
{
//Print the field type as a string
c.App.Output.WriteLine("sample", $"Type: {field.Type}");

if(field.TypeClass != null)
{
//If the field type is a user-defined class, output its fully qualified name.
c.App.Output.WriteLine("sample", $" TypeClass: {field.TypeClass.FullName}");
}

if(field.TypeEnum != null)
{
//If the field type is a user-defined enumeration, output its fully qualified name.
c.App.Output.WriteLine("sample", $" TypeEnum: {field.TypeEnum.FullName}");
}
}
}