Bundt Programmer's Guide · Bundt Programmer's Interface version

And and Edit Type Model Elements

The following example shows how to add some model elements to a type model, and then retrieve and modify them.

Model elements can be usually added by calling the appropriate method on the owner entity. For example, call TypeModel.AddNewClass to add a class to a type model. Once added to a model, elements can be directly manipulated and altered by using a number of collections and properties, as illustrated below.

To execute this code, you will need a reference to the ModellingEngine library.

using Incipit.Bundt.ModellingEngine;

//create a type model.
var tmo = ModelManager.CreateTypeModel("TypeTest", VersionInfo.OneZeroZeroZero);

//add a few classes.
var clAnimal = tmo.AddNewClass("Animal", true);
var clCat = tmo.AddNewClass("Cat", false);
var clDog = tmo.AddNewClass("Dog", false);

//connect the classes via generalization/specialization.
clAnimal.Specialize("Species", clCat, clDog);

//add an attribute.
var attAge = clAnimal.AddNewAttribute("Age", Cardinality.One, BaseDataType.Number);

//find a class in the model.
var clFound = tmo.FindClass("Animal");

//rename the found class.
clFound.Name = "LivingBeing";

//add some comments to its specialized classes.
foreach (var clDescendant in clFound.Specialization.SpecializedClasses)
    clDescendant.Comments = "This class is a descendant of " + clFound.Name;

In lines 7-9, we create three classes by calling AddNewClass, and passing a name and a flag to indicate whether each class is abstract.

In line 12, we connect the classes together through a generalization/specialization relationship, making Cat and Dog subclasses of Animal. To do this, we call Class.Specialize and pass a discriminant name together with the specialized classes.

In line 15, we add an Age attribute to Animal, specifying its cardinality and data type when calling Class.AddNewAttribute.

In line 18, we retrieve a class from the model by its name by calling TypeModel.FindClass. If there are multiple classes that match the passed text, the first that is found will be returned.

In line 21, we change the class name from Animal to LivingBeing. Notice that class names are identifiers, so only alphanumeric characters plus underscores may be used. Changes like this are effective immediately, and any name clashes or other naming issues will be detected on assignment. An exception is thrown if necessary.

Finally, in lines 24-27 we add some comments to every class that specializes from LivingBeing. We can iterate specialized classes through the SpecializedClasses collection of the class' Specialization property.

Contents distributed under a Creative Commons Attribution 4.0 International License · About · Terms of Use · Contact Us · last updated on 08 October 2020