我在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 );
}
}
}
}
答案 0 :(得分:1)