Beispiel #1
0
        public static T Create <T>(IServiceProvider serviceProvider, VsShell.ISelectionContainer selectionContainer)
            where T : Selection, new()
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            T selection = new T();

            selection.m_serviceProvider = serviceProvider;

            // If no selection container provided, initialize it with the current selection in VS
            if (selectionContainer == null)
            {
                VsShell.IVsMonitorSelection monitorService = serviceProvider.GetService(typeof(VsShell.IVsMonitorSelection)) as VsShell.IVsMonitorSelection;
                Debug.Assert(monitorService != null);
                if (monitorService != null)
                {
                    IntPtr ppHier, ppSC;
                    uint   pitemid;
                    VsShell.IVsMultiItemSelect ppMIS;
                    ErrorHandler.ThrowOnFailure(monitorService.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC));

                    if (ppSC != IntPtr.Zero)
                    {
                        selectionContainer = Marshal.GetObjectForIUnknown(ppSC) as VsShell.ISelectionContainer;
                    }
                }
            }
            selection.m_selectionContainer = selectionContainer;

            return(selection);
        }
Beispiel #2
0
        public TaintIssuesSynchronizer(ITaintStore taintStore,
                                       ISonarQubeService sonarQubeService,
                                       ITaintIssueToIssueVisualizationConverter converter,
                                       IConfigurationProvider configurationProvider,
                                       IToolWindowService toolWindowService,
                                       [Import(typeof(VSShell.SVsServiceProvider))] IServiceProvider serviceProvider,
                                       ILogger logger)
        {
            this.taintStore            = taintStore;
            this.sonarQubeService      = sonarQubeService;
            this.converter             = converter;
            this.configurationProvider = configurationProvider;
            this.toolWindowService     = toolWindowService;
            this.logger = logger;

            vsMonitorSelection = (VSShellInterop.IVsMonitorSelection)serviceProvider.GetService(typeof(VSShellInterop.SVsShellMonitorSelection));
            Guid localGuid = TaintIssuesExistUIContext.Guid;

            vsMonitorSelection.GetCmdUIContextCookie(ref localGuid, out contextCookie);
        }