本文整理汇总了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);
}
示例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);
}
示例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));
}
}
示例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();
}
示例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);
}
}
}
}
示例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();
}
}
示例7: GetTextManager
private IVsTextManager GetTextManager(DTE2 application)
{
using (ServiceProvider wrapperSP = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)application))
{
return (IVsTextManager)wrapperSP.GetService(typeof(SVsTextManager));
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
}
}
示例11: VsOutputWindow
public VsOutputWindow(DTE2 dte2)
{
using (
var sp =
new ServiceProvider(
(IServiceProvider) dte2)) {
_output = (IVsOutputWindow) sp.GetService(typeof (SVsOutputWindow));
}
}
示例12: SelectionListener
protected SelectionListener(ServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
this.monSel = serviceProvider.GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
if(this.monSel == null)
{
throw new InvalidOperationException();
}
}
示例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;
}
示例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;
}
}
}
示例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);
}
}
}