예제 #1
0
        /// <summary>
        /// Determines if the Roslyn extensions for Visual Studio are installed.
        /// </summary>
        /// <remarks>
        /// This method caches the result after it is first checked with the IDE.
        /// </remarks>
        /// <param name="serviceProvider">A service provider for accessing global IDE services.</param>
        /// <returns>
        /// <see langword="true"/> if the Roslyn extensions are installed.
        /// <para>-or-</para>
        /// <para><see langword="false"/> if the Roslyn extensions are not installed.</para>
        /// <para>-or-</para>
        /// <para>null if the result of this method has not been cached from a previous call, and <paramref name="serviceProvider"/> is <see langword="null"/> or could not be used to obtain an instance of <see cref="IVsShell"/>.</para>
        /// </returns>
        public static bool?IsRoslynInstalled(IServiceProvider serviceProvider)
        {
            if (roslynInstalled.HasValue)
            {
                return(roslynInstalled);
            }

            if (IsFinalRoslyn)
            {
                roslynInstalled = true;
                return(true);
            }

            if (serviceProvider == null)
            {
                return(null);
            }

            IVsShell vsShell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell;

            if (vsShell == null)
            {
                return(null);
            }

            Guid guid = new Guid("6cf2e545-6109-4730-8883-cf43d7aec3e1");
            int  isInstalled;

            if (ErrorHandler.Succeeded(vsShell.IsPackageInstalled(ref guid, out isInstalled)))
            {
                roslynInstalled = isInstalled != 0;
            }

            return(roslynInstalled);
        }
예제 #2
0
        public static T LoadPackage <T>([NotNull] this IVsShell shell)
            where T : Package
        {
            Requires.NotNull(shell, nameof(shell));

            Guid       guid = typeof(T).GUID;
            IVsPackage package;

            ErrorHandler.ThrowOnFailure(shell.LoadPackage(ref guid, out package));
            return((T)package);
        }
예제 #3
0
        public static T LoadPackage <T>(this IVsShell shell)
            where T : Package
        {
            Contract.Requires <ArgumentNullException>(shell != null, "shell");

            Guid       guid = typeof(T).GUID;
            IVsPackage package;

            ErrorHandler.ThrowOnFailure(shell.LoadPackage(ref guid, out package));
            return((T)package);
        }
예제 #4
0
        private static string GetLocalRegRoot(IServiceProvider serviceProvider)
        {
            IVsShell vsShell = TemplateUtilities.GetService <IVsShell, IVsShell>(serviceProvider);
            Object   obj;

            vsShell.GetProperty((int)__VSSPROPID.VSSPROPID_VirtualRegistryRoot, out obj);
            if (obj != null && obj is string)
            {
                return((string)obj);
            }
            return(null);
        }
예제 #5
0
        public IGlyphFactory GetGlyphFactory(IWpfTextView view, IWpfTextViewMargin margin)
        {
            if (view == null || margin == null)
            {
                return(null);
            }

            if (!_packageLoaded)
            {
                IVsShell   shell = (IVsShell)ServiceProvider.GetService(typeof(SVsShell));
                Guid       guid  = typeof(InheritanceMarginPackage).GUID;
                IVsPackage package;
                ErrorHandler.ThrowOnFailure(shell.LoadPackage(ref guid, out package));
                _packageLoaded = true;
            }

            return(new InheritanceGlyphFactory(this, view, margin));
        }