如何在 UML 关系上应用构造型?会员结束?
我在 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 );
}
}
}
}
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( stereotype );
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将此问题发布到Skinner 的博客 我得到了这个答案:
Visual Studio 2010 SP1 中应提供解决方案。
I posted this question to Skinner's Blog and I got this answer:
A solution should come with Visual Studio 2010 SP1.