編輯器匯入

您可以匯入許多編輯器服務、處理站和訊息代理程式,以提供擴充功能對核心編輯器的不同存取權。 例如,您可以匯 ITextStructureNavigatorSelectorService 入 ,以提供 ITextStructureNavigator 指定內容類型的 。 (此導覽器可讓您在文字緩衝區上執行不同類型的搜尋。

若要使用編輯器匯入,您可以將它匯入為匯出Managed Extensibility Framework 元件元件的類別欄位或屬性。

注意

如需 Managed Extensibility Framework 的詳細資訊,請參閱 Managed Extensibility Framework (MEF)

匯入語法

下列範例示範如何匯入編輯器選項 Factory 服務。

[Import]
internal IEditorOptionsFactoryService EditorOptions { get; set; }

如果您要將服務匯入為欄位而非屬性,您應該在宣告中將它 null 設定為 ,以避免編譯程式警告未指派給變數:

[Import]
internal IEditorOptionsFactoryService m_editorOptions = null;

如需使用匯入的更多範例,請參閱下列逐步解說:

匯入服務提供者

您也可以以相同方式匯 SVsServiceProvider 入 (在元件 Microsoft.VisualStudio.Shell.Immutable.10.0 中找到 的 ,以取得 Visual Studio 服務的存取權:

[Import]
internal SVsServiceProvider ServiceProvider = null;

如需詳細資訊,請參閱 逐步解說:從編輯器延伸模組 存取 DTE 物件。

服務

編輯器服務通常是提供服務的單一實體,而且會跨多個元件共用。

Import 提供
IFileExtensionRegistryService 擴展名與 IContentType 對象之間的關聯性。
IContentTypeRegistryService IContentType 物件的集合。
IVsFontsAndColorsInformationService IVsFontsAndColorsInformation 物件。
IVsEditorAdaptersFactoryService 許多編輯器配接器物件:

IVsCodeWindow

IVsTextBuffer

IVsTextBufferCoordinator

IVsTextView
IIncrementalSearchFactoryService IIncrementalSearch指定文字檢視的物件。
ITextBufferFactoryService ITextBuffer
ITextDocumentFactoryService ITextDocument
IDifferenceService IDifferenceCollection<T>差異的 。
IHierarchicalStringDifferenceService IHierarchicalDifferenceCollection差異的 。
IProjectionBufferFactoryService IProjectionBufferIElisionBuffer
IBufferGraphFactoryService IBufferGraph物件集合的 ITextBuffer
IClassifierAggregatorService IClassifierITextBuffer
IViewClassifierAggregatorService IClassifierITextView
IClassificationFormatMapService IClassificationFormatMapITextView
IEditorFormatMapService IEditorFormatMapITextView
IClassificationTypeRegistryService 維護物件的集合 IClassificationType
IBufferTagAggregatorFactoryService ITagAggregator<T>文字緩衝區的 。
IViewTagAggregatorFactoryService ITagAggregator<T>文字檢視的 。
IEditorOptionsFactoryService IEditorOptions指定範圍的 。
IScrollMapFactoryService IScrollMap文字檢視的 。
ISmartIndentationService ISmartIndentITextView
ISmartIndentationService 透過物件取得自動縮排 ISmartIndentProvider
ITextEditorFactoryService IWpfTextViewHost管理的 IWpfTextView
IFormattedTextSourceFactoryService IFormattedLineSource
IRtfBuilderService 從一組快照集範圍產生 RTF 格式的文字。
ITextAndAdornmentSequencerFactoryService ITextAndAdornmentSequencerITextView
ITextParagraphPropertiesFactoryService TextParagraphProperties 用於格式化檢視中的文字行。
IEditorOperationsFactoryService IEditorOperationsITextView物件。
ITextSearchService 搜尋文字快照集。
ITextStructureNavigatorSelectorService ITextStructureNavigatorITextBufferIContentType
IOutliningManagerService IOutliningManager文字檢視的 。
IGlyphService 標準字元集。
IIntellisenseSessionStackMapService IIntellisenseSessionStackITextView
IWpfKeyboardTrackingService 追蹤鍵盤處理。
IStandardClassificationService 標準 IClassificationType 物件。
ITextUndoHistoryRegistry 維護文字緩衝區與 ITextUndoHistory 對象之間的關聯性。

其他匯入

提供者處理站和訊息代理程式通常是在多個元件中可以有多個實例的實體。

Import 提供
IErrorProviderFactory SimpleTagger<T>指定緩衝區之 型ErrorTag別的 。
ITextMarkerProviderFactory 文字標記標記器( SimpleTagger<T> 類型 TextMarkerTag為 的 )。
IToolTipProviderFactory IToolTipProvider指定ITextView之 的 。
ICompletionBroker ICompletionSession
IQuickInfoBroker IQuickInfoSession
ISignatureHelpBroker ISignatureHelpSession

另請參閱