I run this code in the UML class diagram, and it works fine, but when I try to apply the stereotypes from PropertiesEditor in Visual Studio to end the relationship (FirstRole and SecondRole), the combo stereotypes do not load, even if the stereotypes that apply to the code seem to apply association properties. What should I put in metaclasses in a UML profile other than IProperty?
<metaclassMoniker name="/MyUmlProfile/Microsoft.VisualStudio.Uml.Classes.IProperty"/>
This is the code:
using Microsoft.VisualStudio.Uml.Classes; foreach( IShape shape in currentDiagram.GetSelectedShapes<IElement>() ) { IElement element = shape.GetElement(); foreach( IStereotype stereotype in element.ApplicableStereotypes ) { if( element is Microsoft.VisualStudio.Uml.Classes.IClass ) { IClass classItem = (IClass)element; if( classItem.SuperClasses.Count() > 0 ) { if( stereotype.Name == "SubclassAttribute" ) { element.ApplyStereotype( stereotype ); } } else if( stereotype.Name == "ClassAttribute" ) { element.ApplyStereotype( stereotype ); } } else if( element is Microsoft.VisualStudio.Uml.Classes.IProperty ) { IProperty property = (IProperty)element; if( property.Association != null ) { if( stereotype.Name == "SetAttribute" && property.UpperValue != null && property.UpperValue.ToString() == "*" ) { element.ApplyStereotype( stereotype ); } else if( stereotype.Name == "ManyToOneAttribute" && ( property.UpperValue == null || property.UpperValue.ToString() == "1" ) ) { element.ApplyStereotype( stereotype ); } } else if( stereotype.Name == "PropertyAttribute" ) { element.ApplyStereotype( stereotype ); } } } }
source share