当前位置: 首页>>代码示例>>C#>>正文


C# ServiceProvider.GetService方法代码示例

本文整理汇总了C#中Microsoft.VisualStudio.Shell.ServiceProvider.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceProvider.GetService方法的具体用法?C# ServiceProvider.GetService怎么用?C# ServiceProvider.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudio.Shell.ServiceProvider的用法示例。


在下文中一共展示了ServiceProvider.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetTypeFromString

        public Type GetTypeFromString(string type)
        {
            IServiceProvider serviceProvider = new ServiceProvider(_dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);

            DynamicTypeService typeService = serviceProvider.GetService(typeof(DynamicTypeService)) as DynamicTypeService;

            IVsSolution sln = serviceProvider.GetService(typeof(IVsSolution)) as IVsSolution;

            IVsHierarchy hier;
            sln.GetProjectOfUniqueName(_dte2.ActiveDocument.ProjectItem.ContainingProject.UniqueName, out hier);

            return typeService.GetTypeResolutionService(hier).GetType(type, true);
        }
开发者ID:CarbineCoder,项目名称:ObjectExporter,代码行数:13,代码来源:TypeRetriever.cs

示例2: ProcessRecord

        /// <summary>
        /// The process record.
        /// </summary>
        /// <exception cref="PSInvalidOperationException">
        /// An error occured
        /// </exception>
        protected override void ProcessRecord()
        {
            var project = this.Project as VSProject;

            if (project == null)
            {
                throw new PSInvalidOperationException("Cannot cast the Project object to a VSProject");
            }

            var sp = new ServiceProvider((IOleServiceProvider)project.DTE);

            // Get the toolbox
            var svsToolbox = sp.GetService(typeof(SVsToolbox));

            if (svsToolbox == null)
            {
                throw new PSInvalidOperationException("Cannot get global Toolbox Service (SVsToolbox)");
            }

            var toolbox = svsToolbox as IVsToolbox;

            if (toolbox == null)
            {
                throw new PSInvalidOperationException("Cannot cast Toolbox Service to IVsToolbox");
            }

            toolbox.RemoveTab(this.Category);
        }
开发者ID:IcodeNet,项目名称:cleansolution,代码行数:34,代码来源:RemoveToolboxTabCmdlet.cs

示例3: RunStarted

        /// <summary>
        /// Executes when the wizard starts.
        /// </summary>
        public override void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, Microsoft.VisualStudio.TemplateWizard.WizardRunKind runKind, object[] customParams)
        {
            base.RunStarted(automationObject, replacementsDictionary, runKind, customParams);

            var wizardData = this.TemplateSchema.WizardData.FirstOrDefault();
            if (wizardData != null)
            {
                LoadWizards(wizardData);

                using (var services = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)automationObject))
                {
                    var components = services.GetService<SComponentModel, IComponentModel>();

                    foreach (var wizard in wizards)
                    {
                        TryOrDispose(() => AttributedModelServices.SatisfyImportsOnce(components.DefaultCompositionService, wizard));
                    }
                }
            }

            foreach (var wizard in wizards)
            {
                TryOrDispose(() => wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams));
            }
        }
开发者ID:NuPattern,项目名称:NuPattern,代码行数:28,代码来源:CoordinatorTemplateWizard.cs

示例4: Transform

        private string Transform(string fileName, string source)
        {
            var sp = new ServiceProvider(_site as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
            var vsproj = ((EnvDTE.ProjectItem)(sp.GetService(typeof(EnvDTE.ProjectItem)))).ContainingProject;
            var cm = (IComponentModel)(Package.GetGlobalService(typeof(SComponentModel)));

            var workspace = cm.GetService<VisualStudioWorkspace>();

            var solution = workspace.CurrentSolution;
            var project = solution.Projects.FirstOrDefault(p => p.FilePath == vsproj.FileName);

            var syntaxTrees = Enumerable.Empty<SyntaxTree>();

            if (project != null)
            {
                var c = project.GetCompilationAsync().Result;
                syntaxTrees = c.SyntaxTrees;
            }

            var syntaxTree = CSharpSyntaxTree.ParseText(source);
            var compilation = CSharpCompilation.Create("temp", syntaxTrees.Concat(new[] { syntaxTree }));

            var rewriter = new NotifyPropertyChangedRewriter(fileName, compilation.GetSemanticModel(syntaxTree, true));

            var result = rewriter.Visit(syntaxTree.GetRoot());

            return result.ToFullString();
        }
开发者ID:itowlson,项目名称:torment-roslyn,代码行数:28,代码来源:RoslyniserSingleFileGenerator.cs

示例5: RunFinished

 // Add Silverlight app to the Web project and create test web pages
 public void RunFinished()
 {
     Project silverlightProject = GetSilverlightProject();
     Project webProject = GetWebProject();
     if (webProject != null)
     {
         _dte2.Solution.SolutionBuild.StartupProjects = webProject.UniqueName;
         Properties properties = webProject.Properties;
         ProjectItem aspxTestPage = this.GetAspxTestPage(webProject);
         if (aspxTestPage != null)
         {
             properties.Item("WebApplication.StartPageUrl").Value = aspxTestPage.Name;
             properties.Item("WebApplication.DebugStartAction").Value = 1;
         }
         if (silverlightProject != null)
         {
             IVsHierarchy hierarchy;
             IVsHierarchy hierarchy2;
             silverlightProject.Properties.Item("SilverlightProject.LinkedServerProject").Value = webProject.FullName;
             var sp = _dte2 as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
             IVsSolution service = null;
             using (var provider2 = new ServiceProvider(sp))
             {
                 service = provider2.GetService(typeof(IVsSolution)) as IVsSolution;
             }
             if (((service.GetProjectOfUniqueName(webProject.UniqueName, out hierarchy) == 0) && (hierarchy != null)) && (service.GetProjectOfUniqueName(silverlightProject.UniqueName, out hierarchy2) == 0))
             {
                 ((IVsSilverlightProjectConsumer)hierarchy).LinkToSilverlightProject("ClientBin", true, false, hierarchy2 as IVsSilverlightProject);
             }
         }
     }
 }
开发者ID:ruisebastiao,项目名称:simplemvvmtoolkit,代码行数:33,代码来源:RootWizard.cs

示例6: ShowContextMenu

        public static void ShowContextMenu(ContextMenuStrip contextMenu, DTE dte)
        {
            try
            {
                var serviceProvider = new ServiceProvider(dte as IServiceProvider);

                IVsUIShellOpenDocument sod = (IVsUIShellOpenDocument)serviceProvider.GetService(typeof(SVsUIShellOpenDocument));
                IVsUIHierarchy targetHier;
                uint[] targetId = new uint[1];
                IVsWindowFrame targetFrame;
                int isOpen;
                Guid viewId = new Guid(LogicalViewID.Primary);
                sod.IsDocumentOpen(null, 0, dte.ActiveWindow.Document.FullName,
                                   ref viewId, 0, out targetHier, targetId,
                                   out targetFrame, out isOpen);

                IVsTextView textView = VsShellUtilities.GetTextView(targetFrame);
                TextSelection selection = (TextSelection)dte.ActiveWindow.Document.Selection;
                Microsoft.VisualStudio.OLE.Interop.POINT[] interopPoint = new Microsoft.VisualStudio.OLE.Interop.POINT[1];
                textView.GetPointOfLineColumn(selection.ActivePoint.Line, selection.ActivePoint.LineCharOffset, interopPoint);

                POINT p = new POINT(interopPoint[0].x, interopPoint[0].y);

                ClientToScreen(textView.GetWindowHandle(), p);

                contextMenu.Show(new Point(p.x, p.y));
            }
            catch (Exception)
            {
                contextMenu.Show();
            }
        }
开发者ID:Galad,项目名称:SpecFlow,代码行数:32,代码来源:VsContextMenuManager.cs

示例7: GetTextManager

 private IVsTextManager GetTextManager(DTE2 application)
 {
     using (ServiceProvider wrapperSP = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)application))
     {
         return (IVsTextManager)wrapperSP.GetService(typeof(SVsTextManager));
     }
 }
开发者ID:hxhlb,项目名称:wordlight,代码行数:7,代码来源:WindowWatcher.cs

示例8: VsTextViewCreated

        /// <summary>
        /// Creates a plugin instance when a new text editor is opened
        /// </summary>
        public void VsTextViewCreated(IVsTextView adapter)
        {
            IWpfTextView view = adapterFactory.GetWpfTextView(adapter);
            if (view == null)
                return;

            ITextDocument document;
            if (!docFactory.TryGetTextDocument(view.TextDataModel.DocumentBuffer, out document))
                return;

            IObjectWithSite iows = adapter as IObjectWithSite;
            if (iows == null)
                return;

            System.IntPtr p;
            iows.GetSite(typeof(IServiceProvider).GUID, out p);
            if (p == System.IntPtr.Zero)
                return;

            IServiceProvider isp = Marshal.GetObjectForIUnknown(p) as IServiceProvider;
            if (isp == null)
                return;

            ServiceProvider sp = new ServiceProvider(isp);
            DTE dte = sp.GetService(typeof(DTE)) as DTE;
            sp.Dispose();

            new Plugin(view, document, dte);
        }
开发者ID:xuhdev,项目名称:editorconfig-visualstudio,代码行数:32,代码来源:PluginFactory.cs

示例9: GetWpfTextView

 public static IWpfTextView GetWpfTextView(EnvDTE.DTE dte, IVsTextView viewAdapter)
 {
     using (ServiceProvider sp = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte))
     {
         var svc = (IVsEditorAdaptersFactoryService)sp.GetService(typeof(IVsEditorAdaptersFactoryService));
         return svc.GetWpfTextView(viewAdapter);
     }
 }
开发者ID:pgourlain,项目名称:CodeWeaver,代码行数:8,代码来源:VSTools.cs

示例10: RunStarted

		public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
		{
			var requiredReferences = GetRequiredReferences(replacementsDictionary);

	
			using (var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)automationObject))
			{
				var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
				var installerServices = componentModel.GetService<IVsPackageInstaller>();

				//installerServices.InstallPackage()
				//installerServices.InstallPackage("http://packages.nuget.org", project, "Microsoft.AspNet.SignalR.JS", "1.0.0-alpha2", false);

				var dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE));
				var missingReferences = FindMissingReferences(requiredReferences, installerServices, dte).ToList();

				if (missingReferences.Count > 0)
				{
					var packages = string.Join(", ", missingReferences.Select(r => r.Reference.Package));
					var msg = string.Format("This template requires these references. Do you want to add them using nuget?\n\n{0}", packages);

					var result = MessageBox.Show(Helpers.MainWindow, msg, "Missing packages", MessageBoxButtons.OKCancel, MessageBoxType.Information, MessageBoxDefaultButton.OK);
					if (result == DialogResult.Cancel)
						throw new WizardCancelledException();

					foreach (var missingRef in missingReferences)
					{
						var reference = missingRef.Reference;
						if (!string.IsNullOrEmpty(reference.ExtensionId))
						{
							installerServices.InstallPackagesFromVSExtensionRepository(reference.ExtensionId, false, false, false, missingRef.Project, new Dictionary<string, string>
						{
							{ reference.Package, reference.Version }
						});
						}
						else
						{
							installerServices.InstallPackage("https://packages.nuget.org", missingRef.Project, reference.Package, reference.Version, false);
						}
					}
				}

			}

		}
开发者ID:GilbertoBotaro,项目名称:Eto,代码行数:45,代码来源:CheckRequiredReferences.cs

示例11: VsOutputWindow

 public VsOutputWindow(DTE2 dte2)
 {
     using (
         var sp =
             new ServiceProvider(
                 (IServiceProvider) dte2)) {
         _output = (IVsOutputWindow) sp.GetService(typeof (SVsOutputWindow));
     }
 }
开发者ID:planetmarshall,项目名称:boost_test_extension,代码行数:9,代码来源:VsOutputWindow.cs

示例12: SelectionListener

        protected SelectionListener(ServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.monSel = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            if(this.monSel == null)
            {
                throw new InvalidOperationException();
            }
        }
开发者ID:vestild,项目名称:nemerle,代码行数:10,代码来源:SelectionListener.cs

示例13: RunStarted

		public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
		{
			requiredReferences = GetRequiredReferences(replacementsDictionary).ToList();
			if (runKind == WizardRunKind.AsNewItem)
			{
				using (var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)automationObject))
				{
					var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
					var installerServices = componentModel.GetService<IVsPackageInstaller>();
					var dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE));

					var missingReferences = FindMissingReferences(installerServices, dte).ToList();
					InstallReferences(installerServices, missingReferences);
				}
			}
			else
				this.automationObject = automationObject;

		}
开发者ID:picoe,项目名称:Eto,代码行数:19,代码来源:CheckRequiredReferences.cs

示例14: DocumentProperties

 protected DocumentProperties(CodeWindowManager mgr) {
     this.mgr = mgr;
     this.visible = true;
     if (mgr != null) {
         IOleServiceProvider sp = mgr.CodeWindow as IOleServiceProvider;
         if (sp != null) {
             ServiceProvider site = new ServiceProvider(sp);
             this.tracker = site.GetService(typeof(SVsTrackSelectionEx)) as IVsTrackSelectionEx;
         }
     }
 }
开发者ID:xenocons,项目名称:visualfsharp,代码行数:11,代码来源:DocumentProperties.cs

示例15: Initialize

 private void Initialize(object automationObject)
 {
     using (var serviceProvider = new ServiceProvider((IServiceProvider)automationObject))
     {
         var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
         using (var container = new CompositionContainer(componentModel.DefaultExportProvider))
         {
             container.ComposeParts(this);
         }
     }
 }
开发者ID:Newtopian,项目名称:nuget,代码行数:11,代码来源:TemplateWizard.cs


注:本文中的Microsoft.VisualStudio.Shell.ServiceProvider.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。