次の方法で共有


IVsEditorAdaptersFactoryService Interface

Provides helper methods to switch between interfaces for the earlier Visual Studio editor (for example, IVsTextView) and the equivalent interfaces for the current Visual Studio editor (for example, ITextView). IVsEditorAdaptersFactoryService also has methods to create adapters for IVsTextBuffer, IVsTextView, and IVsCodeWindow.

These adapters provide an implementation of earlier interfaces that is based on the current interfaces (ITextBuffer and ITextView). You can use one of these adapters wherever an earlier type is required.

Namespace:  Microsoft.VisualStudio.Editor
Assembly:  Microsoft.VisualStudio.Editor (in Microsoft.VisualStudio.Editor.dll)

Syntax

'宣言
Public Interface IVsEditorAdaptersFactoryService
public interface IVsEditorAdaptersFactoryService
public interface class IVsEditorAdaptersFactoryService
type IVsEditorAdaptersFactoryService =  interface end
public interface IVsEditorAdaptersFactoryService

The IVsEditorAdaptersFactoryService type exposes the following members.

Methods

  Name Description
Public method CreateVsCodeWindowAdapter Creates an IVsCodeWindow.
Public method CreateVsTextBufferAdapter(IServiceProvider) Creates an IVsTextBuffer.
Public method CreateVsTextBufferAdapter(IServiceProvider, IContentType) Creates an IVsTextBuffer with the specified IContentType.
Public method CreateVsTextBufferAdapterForSecondaryBuffer Creates an IVsTextBuffer for the secondary buffer (used in IVsTextBufferCoordinator) for the specified ITextBuffer.
Public method CreateVsTextBufferCoordinatorAdapter Creates an IVsTextBufferCoordinator.
Public method CreateVsTextViewAdapter(IServiceProvider) Creates an IVsTextView.
Public method CreateVsTextViewAdapter(IServiceProvider, ITextViewRoleSet) Creates an IVsTextView that has a specified set of text view roles.
Public method GetBufferAdapter Gets the text buffer adapter for this text buffer (if it exists).
Public method GetDataBuffer Gets the data buffer of a text buffer adapter. This is the top buffer of the data model buffer graph.
Public method GetDocumentBuffer Gets the document buffer of an IVsTextBuffer adapter. This is the bottom buffer of the data model buffer graph.
Public method GetViewAdapter Gets the IVsTextView adapter for this text view (if it exists).
Public method GetWpfTextView Gets the Window Presentation Foundation (WPF) text view of a text view adapter.
Public method GetWpfTextViewHost Gets the text view host of a text view adapter.
Public method SetDataBuffer Sets the data buffer of a text buffer adapter that is being used together with an IVsTextBufferCoordinator adapter.

Top

Remarks

This is a Managed Extensibility Framework (MEF) component, and should be imported with the following attribute.

[Import]

Examples

For examples about how to import and use this service as a MEF component, see the following walkthroughs:

Walkthrough: Displaying Statement Completion

Walkthrough: Using a Shortcut Key with an Editor Extension

The following code shows how to get this service from the SComponentModel service to create a code window.

using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Editor;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.ComponentModelHost;

public sealed class MyPackage : Package
{
    ...
    private IServiceProvider serviceProvider;
    ...
    IVSCodeWindow CreateCodeWindow()
    {
        IVsEditorAdaptersFactoryService editorAdapterService;
        IComponentModel componentModel = (IComponentModel) GetService(typeof(SComponentModel));
        editorAdapterService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
        IVsTextBuffer textBuffer = adaptersFactory.CreateVsTextBufferAdapter(serviceProvider);
        textBuffer.InitializeContent("text", 4); 
        IVsCodeWindow codeWindow = adaptersFactory.CreateVsCodeWindowAdapter(serviceProvider);
        codeWindow.SetBuffer(textBuffer as IVsTextLines);

        return codeWindow;
    }
}

See Also

Reference

Microsoft.VisualStudio.Editor Namespace