Compartir a través de


IVsExpansionEnumeration Interface

Definition

Represents a list of code snippets for a particular language service.

public interface class IVsExpansionEnumeration
public interface class IVsExpansionEnumeration
__interface IVsExpansionEnumeration
[System.Runtime.InteropServices.ComConversionLoss]
[System.Runtime.InteropServices.Guid("341E80BE-5B26-4DEE-A111-32A8373D1B51")]
[System.Runtime.InteropServices.InterfaceType(1)]
public interface IVsExpansionEnumeration
[System.Runtime.InteropServices.ComConversionLoss]
[System.Runtime.InteropServices.Guid("341E80BE-5B26-4DEE-A111-32A8373D1B51")]
[System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]
public interface IVsExpansionEnumeration
[<System.Runtime.InteropServices.ComConversionLoss>]
[<System.Runtime.InteropServices.Guid("341E80BE-5B26-4DEE-A111-32A8373D1B51")>]
[<System.Runtime.InteropServices.InterfaceType(1)>]
type IVsExpansionEnumeration = interface
[<System.Runtime.InteropServices.ComConversionLoss>]
[<System.Runtime.InteropServices.Guid("341E80BE-5B26-4DEE-A111-32A8373D1B51")>]
[<System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)>]
type IVsExpansionEnumeration = interface
Public Interface IVsExpansionEnumeration
Attributes

Examples

This example shows a method that retrieves an array of VsExpansion structures each of which describes one code snippet for the specified language.

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

Remarks

Code snippets are pieces of code that can be inserted using the Code Snippets Manager. Each snippet is associated with a particular coding language. This interface provides a way to examine the information associated with code snippets for a particular coding language.

Notes to Implementers

This interface is implemented by the expansion manager, which is represented by the IVsExpansionManager interface. Visual Studio typically implements the expansion manager.

Notes to Callers

To obtain this interface, call the EnumerateExpansions(Guid, Int32, String[], Int32, Int32, Int32, IVsExpansionEnumeration) method in the IVsExpansionManager interface. See the Example in this topic.

Methods

GetCount(UInt32)

Returns the number of objects represented in this enumeration.

Next(UInt32, IntPtr[], UInt32)

Returns the specified number of objects from the enumeration.

Reset()

Resets the enumeration to the beginning.

Applies to