How to apply stereotypes on UML Relationships' MemberEnds?
        Posted  
        
            by Cristi Potlog
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Cristi Potlog
        
        
        
        Published on 2010-03-12T16:04:45Z
        Indexed on 
            2010/03/12
            16:07 UTC
        
        
        Read the original article
        Hit count: 700
        
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 == "Set" &&
                    property.UpperValue != null && property.UpperValue.ToString() == "*" )
                {
                    element.ApplyStereotype( stereotype );
                }
                else if( stereotype.Name == "ManyToOne" &&
                    ( property.UpperValue == null || property.UpperValue.ToString() == "1" ) )
                {
                    element.ApplyStereotype( stereotype );
                }
            }
            else if( stereotype.Name == "Property" )
            {
                element.ApplyStereotype( stereotype );
            }
        }
    }
}
        © Stack Overflow or respective owner