views:

35

answers:

1

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!

A: 

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.

Cristi Potlog