1

有没有办法在 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;
        }
    }
}

我被困住了。请帮忙!

4

1 回答 1

0

我不太乐意回答我自己的问题,但事实是所描述的行为是“设计使然”。我正在使用加载在外部类库上的模型存储上运行代码

IModelingProjectReader project = ModelingProject.LoadReadOnly( projectPath )

当从可以访问正在应用的配置文件的 VS 插件运行时,该代码可以完美运行,同时加载适用的构造型。

于 2010-03-03T15:14:52.183 回答