Condividi tramite


Interfaccia IVsExpansionEnumeration

Rappresenta un elenco di frammenti di codice per un servizio di linguaggio particolare.

Spazio dei nomi:  Microsoft.VisualStudio.TextManager.Interop
Assembly:  Microsoft.VisualStudio.TextManager.Interop.8.0 (in Microsoft.VisualStudio.TextManager.Interop.8.0.dll)

Sintassi

'Dichiarazione
<GuidAttribute("341E80BE-5B26-4DEE-A111-32A8373D1B51")> _
<InterfaceTypeAttribute()> _
Public Interface IVsExpansionEnumeration
[GuidAttribute("341E80BE-5B26-4DEE-A111-32A8373D1B51")]
[InterfaceTypeAttribute()]
public interface IVsExpansionEnumeration
[GuidAttribute(L"341E80BE-5B26-4DEE-A111-32A8373D1B51")]
[InterfaceTypeAttribute()]
public interface class IVsExpansionEnumeration
[<GuidAttribute("341E80BE-5B26-4DEE-A111-32A8373D1B51")>]
[<InterfaceTypeAttribute()>]
type IVsExpansionEnumeration =  interface end
public interface IVsExpansionEnumeration

Il tipo IVsExpansionEnumeration espone i seguenti membri.

Metodi

  Nome Descrizione
Metodo pubblico GetCount Restituisce il numero di oggetti rappresentati nell' enumerazione.
Metodo pubblico Next Restituisce il numero specificato degli oggetti dell' enumerazione.
Metodo pubblico Reset Reimposta l'enumerazione all' inizio.

In alto

Note

I frammenti di codice sono parti di codice che possono essere inseriti utilizzando gestione frammenti di codice. Ogni frammento è associato a un particolare linguaggio di programmazione. Questa interfaccia consente di esaminare le informazioni associate ai frammenti di codice per un particolare linguaggio di programmazione.

Note per gli implementatori

Questa interfaccia viene implementata dall' amministratore di espansione, che è rappresentato dall' interfaccia di IVsExpansionManager . Visual Studio in genere implementa la gestione di espansione.

Note per i chiamanti

Per ottenere questa interfaccia, chiamare il metodo di EnumerateExpansions interfaccia di IVsExpansionManager . Vedere l'esempio riportato in questo argomento.

Esempi

In questo esempio viene illustrato un metodo che recupera una matrice di strutture di VsExpansion ognuno dei quali descrive un frammento di codice per il linguaggio specificato.

using System;
using System.Collections;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.TextManager.Interop;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;

namespace MyPackage
{
    public class MyReadSnippets
    {
        private IOleServiceProvider serviceProvider;

        public MyReadSnippets(IOleServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
        }


        private object GetService(Guid serviceGuid, Guid interfaceGuid)
        {
            IntPtr pUnknown = IntPtr.Zero;
            object unknown = null;
            int hr = this.serviceProvider.QueryService(ref serviceGuid,
                                    ref interfaceGuid,
                                    out pUnknown);
            if (ErrorHandler.Succeeded(hr))
            {
                unknown = Marshal.GetObjectForIUnknown(pUnknown);
            }
            return unknown;
        }


        private void GetSnippets(Guid languageGuid,ref ArrayList expansionsList)
        {
            IVsTextManager textManager;
            textmanager = (IVsTextManager)this.GetService(typeof(SVsTextManager).GUID,
                                                          typeof(IVsTextManager).GUID);
            if (textManager != null)
            {
                IVsTextManager2 textManager2 = (IVsTextManager2)textManager;
                if (textManager2 != null)
                {
                    IVsExpansionManager expansionManager = null;
                    textManager2.GetExpansionManager(out expansionManager);
                    if (expansionManager != null)
                    {
                        // Tell the environment to fetch all of our snippets.
                        IVsExpansionEnumeration expansionEnumerator = null;
                        expansionManager.EnumerateExpansions(languageGuid,
                                                             0,     // return all info
                                                             null,  // return all types
                                                             0,     // return all types
                                                             0,     // do not return NULL type
                                                             0,     // do not return duplicates
                                                             out expansionEnumerator);
                        if (expansionEnumerator != null)
                        {
                            // Cache our expansions in an array of
                            // VSExpansion structures.
                            uint count   = 0;
                            uint fetched = 0;
                            VsExpansion expansionInfo = new VsExpansion();
                            IntPtr[] pExpansionInfo   = new IntPtr[1];
                            // Allocate enough memory for one VSExpansion structure.
                            // This memory is filled in by the Next method.
                            pExpansionInfo[0] = Marshal.AllocCoTaskMem(Marshal.SizeOf(expansionInfo));

                            expansionEnumerator.GetCount(out count);
                            for (uint i = 0; i < count; i++)
                            {
                                expansionEnumerator.Next(1, pExpansionInfo, out fetched);
                                if (fetched > 0)
                                {
                                    // Convert the returned blob of data into a
                                    // structure that can be read in managed code.
                                    expansionInfo = (VsExpansion)
                                                    Marshal.PtrToStructure(pExpansionInfo[0],
                                                                           typeof(VsExpansion));

                                    if (!String.IsNullOrEmpty(expansionInfo.shortcut))
                                    {
                                        expansionsList.Add(expansionInfo);
                                    }
                                }
                            }
                            Marshal.FreeCoTaskMem(pExpansionInfo[0]);
                        }
                    }
                }
            }
        }
    }
}

Vedere anche

Riferimenti

Spazio dei nomi Microsoft.VisualStudio.TextManager.Interop