如何在UML Relationships的MemberEnds上应用构造型?

时间:2010-03-12 16:04:46

标签: visual-studio-2010 uml profile vsx

我在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 );
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我已将此问题发布到Skinner's Blog,我得到了这个答案:

  

“不幸的是,这是我们代码中的错误。”

Visual Studio 2010 SP1应该提供解决方案。