編輯器匯入
您可以匯入許多編輯器服務、處理站和訊息代理程式,以提供擴充功能對核心編輯器的不同存取權。 例如,您可以匯 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 物件。
服務
編輯器服務通常是提供服務的單一實體,而且會跨多個元件共用。
其他匯入
提供者處理站和訊息代理程式通常是在多個元件中可以有多個實例的實體。