我在一个UML上运行这段代码,它工作得很好,但是当尝试将来自Visual Studio中的PropertiesEditor的构造型应用于关系结束(FirstRole和SecondRole)时,构造型组合不会加载,即使在代码中似乎有适用于关联属性的构造型有效。除了IProperty之外,我应该在UML profile的元类标签中放些什么?
<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 );
}
}
}
}发布于 2011-04-22 20:08:03
我把这个问题发到了Skinner's Blog上,得到的答案是:
“不幸的是,这是我们代码中的一个错误。”
一个解决方案应该与Visual Studio2010 SP1一起提供。
https://stackoverflow.com/questions/2433970
复制相似问题