public static IEnumerable<IVsHierarchy> GetProjectHierarchies(this IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            Contract.Requires<ArgumentNullException>(solution != null, "solution");
            Contract.Ensures(Contract.Result<IEnumerable<IVsHierarchy>>() != null);

            Guid empty = Guid.Empty;
            IEnumHierarchies ppenum;
            if (ErrorHandler.Succeeded(solution.GetProjectEnum((uint)flags, ref empty, out ppenum)))
            {
                if (ppenum != null)
                {
                    IVsHierarchy[] rgelt = new IVsHierarchy[1];
                    uint celtFetched;
                    for (; ; )
                    {
                        int hr = ppenum.Next((uint)rgelt.Length, rgelt, out celtFetched);
                        ErrorHandler.ThrowOnFailure(hr);

                        for (int i = 0; i < celtFetched; i++)
                            yield return rgelt[i];

                        if (hr == VSConstants.S_FALSE)
                            yield break;
                    }
                }
            }
        }
        public static IEnumerable<IVsHierarchy> EnumerateLoadedProjects(this IVsSolution solution, __VSENUMPROJFLAGS enumFlags)
        {
            var prjType = Guid.Empty;
            IEnumHierarchies ppHier;

            var hr = solution.GetProjectEnum((uint)enumFlags, ref prjType, out ppHier);
            if (ErrorHandler.Succeeded(hr) && ppHier != null)
            {
                uint fetched = 0;
                var hierarchies = new IVsHierarchy[1];
                while (ppHier.Next(1, hierarchies, out fetched) == VSConstants.S_OK)
                {
                    yield return hierarchies[0];
                }
            }
        }
        List<IVsHierarchy> GetProjects(IAnkhServiceProvider context, __VSENUMPROJFLAGS flags)
        {
            IVsSolution solution = context.GetService<IVsSolution>(typeof(SVsSolution));
            Guid gNone = Guid.Empty;
            IEnumHierarchies hierEnum;
            ErrorHandler.ThrowOnFailure(solution.GetProjectEnum((uint)flags, ref gNone, out hierEnum));

            IVsHierarchy[] hiers = new IVsHierarchy[32];
            List<IVsHierarchy> result = new List<IVsHierarchy>();

            uint fetched;
            while(ErrorHandler.Succeeded(hierEnum.Next((uint)hiers.Length, hiers, out fetched)))
            {
                if((int)fetched == hiers.Length)
                    result.AddRange(hiers);
                else if(fetched > 0)
                    for(int i = 0; i < (int)fetched; i++)
                        result.Add(hiers[i]);
                else
                    break;
            }

            return result;
        }
        public static IEnumerable <IVsHierarchy> GetProjectsInSolution(IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            if (solution == null)
            {
                yield break;
            }

            IEnumHierarchies enumHierarchies;
            Guid             guid = Guid.Empty;

            solution.GetProjectEnum((uint)flags, ref guid, out enumHierarchies);
            if (enumHierarchies == null)
            {
                yield break;
            }

            IVsHierarchy[] hierarchy = new IVsHierarchy[1];
            uint           fetched;

            while (enumHierarchies.Next(1, hierarchy, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                if (hierarchy.Length > 0 && hierarchy[0] != null)
                {
                    yield return(hierarchy[0]);
                }
            }
        }
        private static IEnumerable <IVsHierarchy> GetProjectsInSolution([CanBeNull] IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            Contract.Ensures(Contract.Result <IEnumerable <IVsHierarchy> >() != null);

            if (solution == null)
            {
                yield break;
            }

            var guid = Guid.Empty;

            solution.GetProjectEnum((uint)flags, ref guid, out var enumHierarchies);
            if (enumHierarchies == null)
            {
                yield break;
            }

            var hierarchy = new IVsHierarchy[1];

            while (enumHierarchies.Next(1, hierarchy, out var fetched) == VSConstants.S_OK && fetched == 1)
            {
                if (hierarchy.Length > 0 && hierarchy[0] != null)
                {
                    yield return(hierarchy[0]);
                }
            }
        }
Esempio n. 6
0
        public static IEnumerable<IVsHierarchy> GetProjectsInSolution(IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            if (solution == null)
                yield break;

            IEnumHierarchies enumHierarchies;
            Guid guid = Guid.Empty;
            solution.GetProjectEnum((uint)flags, ref guid, out enumHierarchies);
            if (enumHierarchies == null)
                yield break;

            IVsHierarchy[] hierarchy = new IVsHierarchy[1];
            uint fetched;
            while (enumHierarchies.Next(1, hierarchy, out fetched) == VSConstants.S_OK && fetched == 1)
            {
                if (hierarchy.Length > 0 && hierarchy[0] != null)
                    yield return hierarchy[0];
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets all projects in the solution as IVsHierarchy items.
        /// </summary>
        public static IEnumerable <IVsHierarchy> GetAllProjectHierarchys(this IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (solution == null)
            {
                yield break;
            }

            Guid guid = Guid.Empty;

            solution.GetProjectEnum((uint)flags, ref guid, out IEnumHierarchies enumHierarchies);
            if (enumHierarchies == null)
            {
                yield break;
            }

            var hierarchy = new IVsHierarchy[1];

            while (enumHierarchies.Next(1, hierarchy, out var fetched) == VSConstants.S_OK && fetched == 1)
            {
                if (hierarchy.Length > 0 && hierarchy[0] != null)
                {
                    yield return(hierarchy[0]);
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Retrieves an array of all projects in the solution.
        /// </summary>
        public static IEnumerable <Project> GetAllProjects(this IVsSolution solution, __VSENUMPROJFLAGS flags)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            foreach (IVsHierarchy hier in GetAllProjectHierarchys(solution, flags))
            {
                var project = hier.ToProject();

                if (project != null)
                {
                    yield return(project);
                }
            }
        }