다음을 통해 공유


IVsExpansionEnumeration 인터페이스

특정 언어 서비스에코딩하다조각 목록을 나타냅니다.

네임스페이스:  Microsoft.VisualStudio.TextManager.Interop
어셈블리:  Microsoft.VisualStudio.TextManager.Interop.8.0(Microsoft.VisualStudio.TextManager.Interop.8.0.dll)

구문

‘선언
<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

IVsExpansionEnumeration 형식에서는 다음과 같은 멤버를 노출합니다.

메서드

  이름 설명
Public 메서드 GetCount 이열거형에 개체의 수를 반환 합니다.
Public 메서드 Next 지정 된 개체의열거형을 반환합니다.
Public 메서드 Reset 열거형의 시작 부분으로 다시 설정합니다.

위쪽

설명

코드 조각을 코드 조각 관리자를 사용 하 여 삽입할 수 있는코딩하다조각입니다. 각 조각은 특정 코딩 언어와 연결 되어 있습니다. 이인터페이스코딩하다조각은 특정 코딩 언어에 대 한 연결 정보를 검사 하는 방법을 제공 합니다.

구현자 참고 사항

이인터페이스표시 되며 확장 관리자에 구현 되는 IVsExpansionManager인터페이스입니다. Visual Studio일반적으로 확장 관리자를 구현 합니다.

호출자 참고 사항

호출 하 여이인터페이스를 가져올 수 있는 EnumerateExpansions메서드는 IVsExpansionManager인터페이스입니다. 이 항목의 예제를에서 참조 하십시오.

예제

이 예제에서는 배열을 검색 하는메서드보여 줍니다. VsExpansion 는 지정 된 언어에 대 한코딩하다조각을 설명 하는 구조.

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

참고 항목

참조

Microsoft.VisualStudio.TextManager.Interop 네임스페이스