编辑器导入

可以导入许多编辑器服务、工厂和代理,这些服务为扩展提供对核心编辑器的不同类型的访问权限。 例如,可以导入 ITextStructureNavigatorSelectorService 为给定内容类型提供的内容 ITextStructureNavigator 。 (此导航器允许对文本缓冲区执行不同类型的搜索。

若要使用编辑器导入,请将其导入为导出托管扩展性框架组件部件的类的字段或属性。

注意

有关托管扩展性框架的详细信息,请参阅托管扩展性框架(MEF)。

导入语法

以下示例演示如何导入编辑器选项工厂服务。

[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 一 IProjectionBuffer 个或一个 IElisionBuffer。
IBufferGraphFactoryService 一组ITextBuffer对象的值IBufferGraph。
IClassifierAggregatorService 一 IClassifier 个 ITextBuffer。
IViewClassifierAggregatorService 一 IClassifier 个 ITextView。
IClassificationFormatMapService 一 IClassificationFormatMap 个 ITextView。
IEditorFormatMapService 一 IEditorFormatMap 个 ITextView。
IClassificationTypeRegistryService 维护对象的集合 IClassificationType 。
IBufferTagAggregatorFactoryService 文本缓冲区的一 ITagAggregator<T> 个。
IViewTagAggregatorFactoryService 文本视图的一 ITagAggregator<T> 个。
IEditorOptionsFactoryService 指定 IEditorOptions 范围。
IScrollMapFactoryService 文本视图的一 IScrollMap 个。
ISmartIndentationService 一 ISmartIndent 个 ITextView。
ISmartIndentationService 获取对象的 ISmartIndentProvider 自动缩进。
ITextEditorFactoryService 管理一 IWpfTextViewHost 个 IWpfTextView.
IFormattedTextSourceFactoryService IFormattedLineSource。
IRtfBuilderService 从一组快照范围生成 RTF 格式的文本。
ITextAndAdornmentSequencerFactoryService 一 ITextAndAdornmentSequencer 个 ITextView.
ITextParagraphPropertiesFactoryService 用于 TextParagraphProperties 设置视图中文本行的格式。
IEditorOperationsFactoryService 对象的 IEditorOperations 对象 ITextView。
ITextSearchService 搜索文本快照。
ITextStructureNavigatorSelectorService 一 ITextStructureNavigator 个 ITextBuffer by IContentType.
IOutliningManagerService 文本视图的一 IOutliningManager 个。
IGlyphService 一组标准字形。
IIntellisenseSessionStackMapService 一 IIntellisenseSessionStack 个 ITextView。
IWpfKeyboardTrackingService 跟踪键盘处理。
IStandardClassificationService 标准 IClassificationType 对象。
ITextUndoHistoryRegistry 维护文本缓冲区和 ITextUndoHistory 对象之间的关系。

其他导入

提供程序工厂和代理通常是可以在多个组件中具有多个实例的实体。

Import 提供
IErrorProviderFactory SimpleTagger<T>给定缓冲区的类型 ErrorTag。
ITextMarkerProviderFactory 文本标记标记器( SimpleTagger<T> 类型 TextMarkerTag)。
IToolTipProviderFactory 一 IToolTipProvider 个给定 ITextView的 。
ICompletionBroker ICompletionSession。
IQuickInfoBroker IQuickInfoSession。
ISignatureHelpBroker ISignatureHelpSession。

另请参阅