/// <summary>
        /// Gets a service from the MEF component catalog
        /// </summary>
        public static TInterface GetMefService <TInterface>() where TInterface : class
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            IComponentModel2 compService = GetRequiredService <SComponentModel, IComponentModel2>();

            return(compService.GetService <TInterface>());
        }
        /// <summary>Gets the WPF text view from the currently active document.</summary>
        public async Task <IWpfTextView?> GetCurrentWpfTextViewAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IComponentModel2 compService = await VS.GetRequiredServiceAsync <SComponentModel, IComponentModel2>();

            IVsEditorAdaptersFactoryService?editorAdapter = compService.GetService <IVsEditorAdaptersFactoryService>();
            IVsTextView viewAdapter = await GetCurrentNativeTextViewAsync();

            return(editorAdapter?.GetWpfTextView(viewAdapter));
        }
        /// <summary>
        /// Gets a service from the MEF component catalog
        /// </summary>
        public static async Task <TInterface> GetMefServiceAsync <TInterface>() where TInterface : class
        {
            IComponentModel2 compService = await GetRequiredServiceAsync <SComponentModel, IComponentModel2>();

            return(compService.GetService <TInterface>());
        }
Esempio n. 4
0
 public Globals()
 {
     this.DTE = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
     this.MEF = (Microsoft.VisualStudio.ComponentModelHost.IComponentModel2)Package.GetGlobalService(typeof(Microsoft.VisualStudio.ComponentModelHost.SComponentModel));
 }