【问题标题】:How to get a IStereotype reference in a T4 Template?如何在 T4 模板中获取 Istereotype 参考?
【发布时间】:2010-03-02 00:57:15
【问题描述】:

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

我被困住了。请帮忙!

【问题讨论】:

    标签: visual-studio-2010 profile extensibility uml stereotype


    【解决方案1】:

    我不太乐意回答我自己的问题,但事实是所描述的行为是“设计”。 我正在使用

    在外部类库上加载的模型存储上运行代码
    IModelingProjectReader project = ModelingProject.LoadReadOnly( projectPath )
    

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

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 2022-12-15
      • 1970-01-01
      • 2012-02-18
      相关资源
      最近更新 更多