开发者

How to get a IStereotype reference in a T4 Template?

Is there a way to get a reference to Microsoft.VisualStudio.Uml.Profiles.IStereotype interface in a t4 template? I mean IStereotype that stores the definition of the UML stereotype, and not IStereotypeInstance that holds the actual value. I tried something like this, but the ApplicableStereotypes enumereation is empty.

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 ) );
    }
}

I tried to get IStereotype from ModelStore. But ProfileManager property always returns null and the code breaks.

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;
        }
    }
}

I'm stucked. Please help!


I'm not that happy to answer my own question, but the fact is that the described behaviour is "by design". I was running the code on a model store loaded on an external class library using

IModelingProjectReader project = ModelingProject.LoadReadOnly( projectPath )

The code works perfectly when running from an VS Add-in that has access to the profile that is being applied, loading the applicable stereotypes too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜