我在 UML 类图上运行此代码,它工作得很好,但是当尝试从 Visual Studio 中的 PropertiesEditor 应用构造型用于关系结束(FirstRole 和 SecondRole)时,即使在代码中也不会加载构造型组合似乎适用于对关联属性有效的刻板印象。除了 IProperty,我应该在 UML 配置文件中的元类标记中添加什么?
<metaclassMoniker name="/MyUmlProfile/Microsoft.VisualStudio.Uml.Classes.IProperty"/>
这是代码:
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 );
}
}
}
}