本文整理汇总了C#中IServiceProvider.GetMefService方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceProvider.GetMefService方法的具体用法?C# IServiceProvider.GetMefService怎么用?C# IServiceProvider.GetMefService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IServiceProvider
的用法示例。
在下文中一共展示了IServiceProvider.GetMefService方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProjectExternalErrorReporter
public ProjectExternalErrorReporter(ProjectId projectId, string errorCodePrefix, IServiceProvider serviceProvider)
{
_projectId = projectId;
_errorCodePrefix = errorCodePrefix;
_diagnosticProvider = serviceProvider.GetMefService<ExternalErrorDiagnosticUpdateSource>();
_workspace = serviceProvider.GetMefService<VisualStudioWorkspaceImpl>();
Debug.Assert(_diagnosticProvider != null);
Debug.Assert(_workspace != null);
}
示例2: SonarAnalyzerManager
internal /*for testing purposes*/ SonarAnalyzerManager(IServiceProvider serviceProvider, Workspace workspace,
ISolutionAnalysisRequester solutionAnalysisRequester)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
if (workspace == null)
{
throw new ArgumentNullException(nameof(workspace));
}
this.workspace = workspace;
this.activeSolutionBoundTracker = serviceProvider.GetMefService<IActiveSolutionBoundTracker>();
if (this.activeSolutionBoundTracker == null)
{
Debug.Fail($"Could not get {nameof(IActiveSolutionBoundTracker)}");
}
this.solutionAnalysisRequester = solutionAnalysisRequester;
this.activeSolutionBoundTracker.SolutionBindingChanged += this.ActiveSolutionBoundTracker_SolutionBindingChanged;
SonarAnalysisContext.ShouldAnalysisBeDisabled =
tree => ShouldAnalysisBeDisabledOnTree(tree);
}
示例3: NavigationBarClient
public NavigationBarClient(
IVsDropdownBarManager manager,
IVsCodeWindow codeWindow,
IServiceProvider serviceProvider,
VisualStudioWorkspaceImpl workspace)
{
_manager = manager;
_codeWindow = codeWindow;
_workspace = workspace;
_imageService = (IVsImageService2)serviceProvider.GetService(typeof(SVsImageService));
_projectItems = SpecializedCollections.EmptyList<NavigationBarProjectItem>();
_currentTypeItems = SpecializedCollections.EmptyList<NavigationBarItem>();
var vsShell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;
if (vsShell != null)
{
object varImageList;
int hresult = vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_ObjectMgrTypesImgList, out varImageList);
if (ErrorHandler.Succeeded(hresult) && varImageList != null)
{
_imageList = (IntPtr)(int)varImageList;
}
}
_codeWindowEventsSink = ComEventSink.Advise<IVsCodeWindowEvents>(codeWindow, this);
_editorAdaptersFactoryService = serviceProvider.GetMefService<IVsEditorAdaptersFactoryService>();
IVsTextView pTextView;
codeWindow.GetPrimaryView(out pTextView);
StartTrackingView(pTextView);
pTextView = null;
codeWindow.GetSecondaryView(out pTextView);
StartTrackingView(pTextView);
}
示例4: InvisibleEditor
public InvisibleEditor(IServiceProvider serviceProvider, string filePath, bool needsSave, bool needsUndoDisabled)
{
_serviceProvider = serviceProvider;
_filePath = filePath;
_needsSave = needsSave;
var invisibleEditorManager = (IIntPtrReturningVsInvisibleEditorManager)serviceProvider.GetService(typeof(SVsInvisibleEditorManager));
var invisibleEditorPtr = IntPtr.Zero;
Marshal.ThrowExceptionForHR(invisibleEditorManager.RegisterInvisibleEditor(filePath, null, 0, null, out invisibleEditorPtr));
try
{
_invisibleEditor = (IVsInvisibleEditor)Marshal.GetUniqueObjectForIUnknown(invisibleEditorPtr);
var docDataPtr = IntPtr.Zero;
Marshal.ThrowExceptionForHR(_invisibleEditor.GetDocData(fEnsureWritable: needsSave ? 1 : 0, riid: typeof(IVsTextLines).GUID, ppDocData: out docDataPtr));
try
{
var docData = Marshal.GetObjectForIUnknown(docDataPtr);
_vsTextLines = docData as IVsTextLines;
var vsTextBuffer = (IVsTextBuffer)docData;
var editorAdapterFactoryService = serviceProvider.GetMefService<IVsEditorAdaptersFactoryService>();
_buffer = editorAdapterFactoryService.GetDocumentBuffer(vsTextBuffer);
if (needsUndoDisabled)
{
Marshal.ThrowExceptionForHR(vsTextBuffer.GetUndoManager(out _manager));
int isEnabled;
Marshal.ThrowExceptionForHR((_manager as IVsUndoState).IsEnabled(out isEnabled));
_needsUndoRestored = isEnabled != 0;
if (_needsUndoRestored)
{
_manager.DiscardFrom(null); // Discard the undo history for this document
_manager.Enable(0); // Disable Undo for this document
}
}
}
finally
{
Marshal.Release(docDataPtr);
}
}
finally
{
// We need to clean up the extra reference we have, now that we have an RCW holding onto the object.
Marshal.Release(invisibleEditorPtr);
}
}