开发者

How to apply stereotypes on UML Relationships' MemberEnds?

I'm running this code on a UML Class Diagram, and it works just fine, but when trying to apply stereotypes from PropertiesEditor in Visual Studio for relationship ends (FirstRole and SecondRole), the stereotypes combo doesn't load even if in code there seems to be applicable stereotypes valid for association properties. What should I put in metaclasses tag in the UML profile except for 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( s开发者_StackOverflow中文版tereotype );
            }
        }
    }
}


I posted this question to Skinner's Blog and I got this answer:

"Unfortunately, this is a bug in our code."

A solution should come with Visual Studio 2010 SP1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜