Partilhar via


Método IVsExtensionManager.GetEnabledExtensionContentLocations (String, IDictionary<String, String>)

Consultas de uma coleção dos caminhos de todo o conteúdo de um tipo específico que está incluído nas extensões ativadas e, em seguida, filtra os resultados comparando os determinados atributos para os atributos XML no nó do conteúdo.

Namespace:  Microsoft.VisualStudio.ExtensionManager
Assembly:  Microsoft.VisualStudio.ExtensionManager (em Microsoft.VisualStudio.ExtensionManager.dll)

Sintaxe

'Declaração
Function GetEnabledExtensionContentLocations ( _
    contentTypeName As String, _
    attributes As IDictionary(Of String, String) _
) As IEnumerable(Of String)
IEnumerable<string> GetEnabledExtensionContentLocations(
    string contentTypeName,
    IDictionary<string, string> attributes
)
IEnumerable<String^>^ GetEnabledExtensionContentLocations(
    String^ contentTypeName, 
    IDictionary<String^, String^>^ attributes
)
abstract GetEnabledExtensionContentLocations : 
        contentTypeName:string * 
        attributes:IDictionary<string, string> -> IEnumerable<string> 
function GetEnabledExtensionContentLocations(
    contentTypeName : String, 
    attributes : IDictionary<String, String>
) : IEnumerable<String>

Parâmetros

  • contentTypeName
    Tipo: String

    O tipo de conteúdo para filtrar a pesquisa por.

  • attributes
    Tipo: IDictionary<String, String>

    Os atributos do conteúdo para corresponder.

Valor de retorno

Tipo: IEnumerable<String>
Uma coleção de caminhos de extensões onde contentTypeName corresponde a um filho a conteúdo elemento do manifesto para a extensão, VSIX e attributes correspondem aos atributos desse elemento filho XML.

Comentários

Embora essa API oferece suporte a Extension Manager infra-estrutura, é recomendável que você não usá-lo porque ele está sujeito a alterações.

Exemplos

O exemplo a seguir usa GetEnabledExtensionContentLocations para obter os locais de todas as extensões de um determinado tipo personalizado. Em seguida, usa CreateExtension para acessar os outros metadados para cada extensão encontrado e obtenha o seu nome. Depois de salvar os nomes e informações de caminho, ele cria os comandos de menu para cada extensão.

// This is the CommandID of the placeholder menu item,  
// as defined in the .vsct file. 
int CmdIdBase = 0x103;

// These lists will store name and path information. 
private ArrayList SkinNames = new ArrayList();
private ArrayList SkinPaths = new ArrayList();

// Call this from Initialize(). 
private void InitSkinList()
{
    var mcs = GetService(typeof(IMenuCommandService)) 
        as OleMenuCommandService;
    int counter = CmdIdBase;

    // Get the Extension Manager service. 
    var ExtMgrSvc = GetService(typeof(SVsExtensionManager)) 
        as IVsExtensionManager;

    // Iterate through installed extensions. 
    var attributes = new Dictionary<string, string>();
    attributes.Add("Type", "Skin");
    foreach (string SkinPath
        in ExtMgrSvc.GetEnabledExtensionContentLocations(
        "CustomExtension", attributes))
    {
        // Store the name and path information.
        SkinPaths.Add(SkinPath);
        SkinNames.Add(ExtMgrSvc.CreateExtension(SkinPath).Header.Name);

        // Create a CommandID for the new menu item. 
        var cmdID = new CommandID(
            GuidList.guidVSSkinHostCmdSet, counter);

        // Create the menu item and add its event handlers. 
        var mc = new OleMenuCommand(
            new EventHandler(OnSkinExec), cmdID);
        mc.BeforeQueryStatus += new EventHandler(OnSkinQueryStatus);
        mcs.AddCommand(mc);

        counter ++;
    }
}

private void OnSkinQueryStatus(object sender, EventArgs e)
{
    var menuCommand = sender as OleMenuCommand;
    if (null != menuCommand)
    {
        // Determine which menu item was queried. 
        int skinIndex = menuCommand.CommandID.ID - this.CmdIdBase;
        if (skinIndex >= 0 && skinIndex < this.SkinNames.Count)
        {
            // Set the text.
            menuCommand.Text = this.SkinNames[skinIndex] as string;
        }
    }
}

private void OnSkinExec(object sender, EventArgs e)
{
    var menuCommand = sender as OleMenuCommand;
    if (null != menuCommand)
    {
        // Get the name of the skin from the menu item. 
        string skinName = menuCommand.Text;

        // Locate the name in the list of skins.  
        int i = this.SkinNames.IndexOf(skinName);

        // Get the corrsponding path. 
        var skinPath = SkinPaths[i] as string;

        if (SkinNames.Count > 0)
        {         
            if (File.Exists(skinPath) || Directory.Exists(skinPath))
            {
                // Put code here to apply the skin extension...
                MessageBox.Show("Skin " + skinName + " found:\r\n" 
                    + skinPath + ". \r\n\r\nApplying skin...");
            }
           else MessageBox.Show("Could not find skin " + skinName);
        }
    }
}

Segurança do .NET Framework

Consulte também

Referência

IVsExtensionManager Interface

Sobrecargas GetEnabledExtensionContentLocations

Namespace Microsoft.VisualStudio.ExtensionManager