本文整理汇总了C#中System.IServiceProvider.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetService方法的具体用法?C# IServiceProvider.GetService怎么用?C# IServiceProvider.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenameDocument
/// <summary>
/// Rename document in the running document table from oldName to newName.
/// </summary>
/// <param name="provider">The service provider.</param>
/// <param name="oldName">Full path to the old name of the document.</param>
/// <param name="newName">Full path to the new name of the document.</param>
/// <param name="newItemId">The new item id of the document</param>
public static void RenameDocument(IServiceProvider site, string oldName, string newName, uint newItemId)
{
if(site == null)
{
throw new ArgumentNullException("site");
}
if(String.IsNullOrEmpty(oldName))
{
throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "oldName");
}
if(String.IsNullOrEmpty(newName))
{
throw new ArgumentException(SR.GetString(SR.ParameterCannotBeNullOrEmpty, CultureInfo.CurrentUICulture), "newName");
}
if(newItemId == VSConstants.VSITEMID_NIL)
{
throw new ArgumentNullException("newItemId");
}
IVsRunningDocumentTable pRDT = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
IVsUIShellOpenDocument doc = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
if(pRDT == null || doc == null) return;
IVsHierarchy pIVsHierarchy;
uint itemId;
IntPtr docData;
uint uiVsDocCookie;
ErrorHandler.ThrowOnFailure(pRDT.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, oldName, out pIVsHierarchy, out itemId, out docData, out uiVsDocCookie));
if(docData != IntPtr.Zero)
{
try
{
IntPtr pUnk = Marshal.GetIUnknownForObject(pIVsHierarchy);
Guid iid = typeof(IVsHierarchy).GUID;
IntPtr pHier;
Marshal.QueryInterface(pUnk, ref iid, out pHier);
try
{
ErrorHandler.ThrowOnFailure(pRDT.RenameDocument(oldName, newName, pHier, newItemId));
}
finally
{
if(pHier != IntPtr.Zero)
Marshal.Release(pHier);
if(pUnk != IntPtr.Zero)
Marshal.Release(pUnk);
}
}
finally
{
Marshal.Release(docData);
}
}
}
示例2: TextViewFilter
public TextViewFilter(IServiceProvider serviceProvider, IVsTextView vsTextView) {
var compModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
_vsEditorAdaptersFactoryService = compModel.GetService<IVsEditorAdaptersFactoryService>();
_debugger = (IVsDebugger)serviceProvider.GetService(typeof(IVsDebugger));
vsTextView.GetBuffer(out _vsTextLines);
_wpfTextView = _vsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
ErrorHandler.ThrowOnFailure(vsTextView.AddCommandFilter(this, out _next));
}
示例3: TextInformationManager
public TextInformationManager(IServiceProvider serviceProvider, IComponentModel componentModel)
{
this.serviceProvider = serviceProvider;
this.componentModel = componentModel;
fontAndColorStorage = (IVsFontAndColorStorage) serviceProvider.GetService(typeof (SVsFontAndColorStorage));
fontAndColorUtilities = fontAndColorStorage as IVsFontAndColorUtilities;
fontAndColorCache = (IVsFontAndColorCacheManager)serviceProvider.GetService(typeof(SVsFontAndColorCacheManager));
textManager = (IVsTextManager) serviceProvider.GetService(typeof (SVsTextManager));
editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();
textStructureNavigatorSelectorService = componentModel.GetService<ITextStructureNavigatorSelectorService>();
classicationFormatMapService = componentModel.GetService<IClassificationFormatMapService>();
classificationAggregatorService = componentModel.GetService<IClassifierAggregatorService>();
}
示例4: TextManager
internal TextManager(
IVsAdapter adapter,
ITextDocumentFactoryService textDocumentFactoryService,
ITextBufferFactoryService textBufferFactoryService,
ISharedService sharedService,
SVsServiceProvider serviceProvider)
{
_vsAdapter = adapter;
_serviceProvider = serviceProvider;
_textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
_textDocumentFactoryService = textDocumentFactoryService;
_textBufferFactoryService = textBufferFactoryService;
_runningDocumentTable = _serviceProvider.GetService<SVsRunningDocumentTable, IVsRunningDocumentTable>();
_sharedService = sharedService;
}
示例5: ShowMessageBox
/// <summary>
/// Use this instead of VsShellUtilities.ShowMessageBox because VSU uses ThreadHelper which
/// uses a private interface that can't be mocked AND goes to the global service provider.
/// </summary>
public static int ShowMessageBox(IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton) {
IVsUIShell uiShell = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
Debug.Assert(uiShell != null, "Could not get the IVsUIShell object from the services exposed by this serviceprovider");
if (uiShell == null) {
throw new InvalidOperationException();
}
Guid emptyGuid = Guid.Empty;
int result = 0;
serviceProvider.GetUIThread().Invoke(() => {
ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
0,
ref emptyGuid,
title,
message,
null,
0,
msgButton,
defaultButton,
icon,
0,
out result));
});
return result;
}
示例6: EmptyTaskList
/// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="VsShellUtilities.EmptyTaskList"]/*' />
/// <devdoc>
/// Empty the task list.
/// </devdoc>
/// <param name="serviceProvider">The service provider.</param>
/// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code. </returns>
public static int EmptyTaskList(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentException("serviceProvider");
}
IVsTaskList taskList = serviceProvider.GetService(typeof(IVsTaskList)) as IVsTaskList;
if (taskList == null)
{
throw new InvalidOperationException();
}
IVsEnumTaskItems enumTaskItems;
int result = VSConstants.S_OK;
try
{
ErrorHandler.ThrowOnFailure(taskList.EnumTaskItems(out enumTaskItems));
if (enumTaskItems == null)
{
throw new InvalidOperationException();
}
// Retrieve the task item text and check whether it is equal with one that supposed to be thrown.
uint[] fetched = new uint[1];
do
{
IVsTaskItem[] taskItems = new IVsTaskItem[1];
result = enumTaskItems.Next(1, taskItems, fetched);
if (fetched[0] == 1)
{
IVsTaskItem2 taskItem = taskItems[0] as IVsTaskItem2;
if (taskItem != null)
{
int canDelete;
ErrorHandler.ThrowOnFailure(taskItem.CanDelete(out canDelete));
if (canDelete == 1)
{
ErrorHandler.ThrowOnFailure(taskItem.OnDeleteTask());
}
}
}
} while (result == VSConstants.S_OK && fetched[0] == 1);
}
catch (COMException e)
{
Trace.WriteLine("Exception : " + e.Message);
result = e.ErrorCode;
}
return result;
}
示例7: TextManager
internal TextManager(
IVsAdapter adapter,
SVsServiceProvider serviceProvider)
{
_adapter = adapter;
_serviceProvider = serviceProvider;
_textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
_table = new RunningDocumentTable(_serviceProvider);
}
示例8: AbstractObjectBrowserLibraryManager
protected AbstractObjectBrowserLibraryManager(string languageName, Guid libraryGuid, IServiceProvider serviceProvider)
: base(libraryGuid, serviceProvider)
{
_languageName = languageName;
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
this.Workspace = componentModel.GetService<VisualStudioWorkspace>();
this.Workspace.WorkspaceChanged += OnWorkspaceChanged;
}
示例9: AbstractObjectBrowserLibraryManager
protected AbstractObjectBrowserLibraryManager(string languageName, Guid libraryGuid, __SymbolToolLanguage preferredLanguage, IServiceProvider serviceProvider)
: base(libraryGuid, serviceProvider)
{
_languageName = languageName;
_preferredLanguage = preferredLanguage;
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
this.Workspace = componentModel.GetService<VisualStudioWorkspace>();
this.LibraryService = this.Workspace.Services.GetLanguageServices(languageName).GetService<ILibraryService>();
this.Workspace.WorkspaceChanged += OnWorkspaceChanged;
}
示例10: IsVisualStudioInDesignMode
/// <summary>
/// Look in the registry under the current hive for the path
/// of MSBuild
/// </summary>
/// <returns></returns>
/// <summary>
/// Is Visual Studio in design mode.
/// </summary>
/// <param name="serviceProvider">The service provider.</param>
/// <returns>true if visual studio is in design mode</returns>
public static bool IsVisualStudioInDesignMode(IServiceProvider site) {
Utilities.ArgumentNotNull("site", site);
IVsMonitorSelection selectionMonitor = site.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
uint cookie = 0;
int active = 0;
Guid designContext = VSConstants.UICONTEXT_DesignMode;
ErrorHandler.ThrowOnFailure(selectionMonitor.GetCmdUIContextCookie(ref designContext, out cookie));
ErrorHandler.ThrowOnFailure(selectionMonitor.IsCmdUIContextActive(cookie, out active));
return active != 0;
}
示例11: GoToDefinitionFilterProvider
public GoToDefinitionFilterProvider([Import(typeof(SVsServiceProvider))] System.IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
var dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
var events = dte.Events as Events2;
if (events != null)
{
this.solutionEvents = events.SolutionEvents;
this.solutionEvents.AfterClosing += Cleanup;
}
}
示例12: IsInAutomationFunction
/// <include file='doc\VsShellUtilities.uex' path='docs/doc[@for="Utilities.IsInAutomationFunction"]/*' />
/// <devdoc>
/// Is an extensibility object executing an automation function.
/// </devdoc>
/// <param name="serviceProvider">The service provider.</param>
/// <returns>true if the extensiblity object is executing an automation function.</returns>
public static bool IsInAutomationFunction(IServiceProvider serviceProvider) {
Utilities.ArgumentNotNull("serviceProvider", serviceProvider);
IVsExtensibility3 extensibility = serviceProvider.GetService(typeof(EnvDTE.IVsExtensibility)) as IVsExtensibility3;
if (extensibility == null) {
throw new InvalidOperationException();
}
int inAutomation = 0;
ErrorHandler.ThrowOnFailure(extensibility.IsInAutomationFunction(out inAutomation));
return inAutomation != 0;
}
示例13: SolutionListener
protected SolutionListener(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
this.solution = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution;
Debug.Assert(this.solution != null, "Could not get the IVsSolution object from the services exposed by this project");
if (this.solution == null)
{
throw new InvalidOperationException();
}
}
示例14: TextManager
internal TextManager(
IVsAdapter adapter,
ITextDocumentFactoryService textDocumentFactoryService,
ITextBufferFactoryService textBufferFactoryService,
SVsServiceProvider serviceProvider)
{
_vsAdapter = adapter;
_serviceProvider = serviceProvider;
_textManager = _serviceProvider.GetService<SVsTextManager, IVsTextManager>();
_textDocumentFactoryService = textDocumentFactoryService;
_textBufferFactoryService = textBufferFactoryService;
_table = new RunningDocumentTable(_serviceProvider);
}
示例15: SubscribeForumCommandStatusChanged
public IDisposable SubscribeForumCommandStatusChanged(
IServiceProvider provider, Action handler)
{
var activeForumSvc = provider.GetService<IActiveForumService>();
if (activeForumSvc != null)
{
CodeJam.Extensibility.EventHandler<IActiveForumService> statusUpdater = sender => handler();
activeForumSvc.ActiveForumChanged += statusUpdater;
return Disposable.Create(
() => activeForumSvc.ActiveForumChanged -= statusUpdater);
}
return Disposable.Empty;
}