有没有办法在 t4 模板中获取对 Microsoft.VisualStudio.Uml.Profiles.IStereotype 接口的引用?我的意思是存储 UML 原型定义的 IStereotype,而不是保存实际值的 IStereotypeInstance。我试过这样的东西,但 ApplicableStereotypes 枚举是空的。
void WriteClassAttributes( IClass classItem )
{
foreach( IStereotypeInstance stereoInst in classItem.AppliedStereotypes )
{
this.WriteLine( string.Format( "{0} = {1}", stereoInst.Profile, stereoInst.Name ) );
}
foreach( IStereotype stereo in classItem.ApplicableStereotypes )
{
this.WriteLine( string.Format( "{0} = {1}", stereo.Profile.Name, stereo.Name ) );
}
}
我试图从 ModelStore 获取 IStereotype。但是 ProfileManager 属性总是返回 null 并且代码中断。
string GetDefaultValue( IStereotypePropertyInstance stereoProp )
{
IModelStore modelStore = stereoProp.GetModelStore();
Microsoft.VisualStudio.Uml.Profiles.IProfile profile =
modelStore.ProfileManager.GetProfileByName( profileName );
foreach( IStereotype stereo in profile.Stereotypes )
{
if( stereo.Name == stereoProp.StereotypeInstance.Name )
{
return stereo.DefaultValue;
}
}
}
我被困住了。请帮忙!