本文整理汇总了C#中IVsSolution.GetProjectEnum方法的典型用法代码示例。如果您正苦于以下问题:C# IVsSolution.GetProjectEnum方法的具体用法?C# IVsSolution.GetProjectEnum怎么用?C# IVsSolution.GetProjectEnum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVsSolution
的用法示例。
在下文中一共展示了IVsSolution.GetProjectEnum方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProjectsInSolution
internal static IEnumerable<IVsHierarchy> GetProjectsInSolution(IVsSolution solution)
{
if (solution == null)
{
throw new ArgumentNullException("solution");
}
IEnumHierarchies penum = null;
var nullGuid = Guid.Empty;
var hr = solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref nullGuid, out penum);
if (ErrorHandler.Succeeded(hr)
&& (penum != null))
{
uint fetched = 0;
var rgelt = new IVsHierarchy[1];
while (penum.Next(1, rgelt, out fetched) == 0
&& fetched == 1)
{
yield return rgelt[0];
}
}
}
示例2: GetProjects
// Traditional VS traversal via enumeration.
public static EnvDTE.Project[] GetProjects(IVsSolution solution, string projectKind = null)
{
var projects = new List<Project>();
if (solution == null)
{
return projects.ToArray();
}
IEnumHierarchies ppEnum;
Guid tempGuid = Guid.Empty;
solution.GetProjectEnum((uint)Microsoft.VisualStudio.Shell.Interop.__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref tempGuid, out ppEnum);
if (ppEnum != null)
{
uint actualResult = 0;
IVsHierarchy[] nodes = new IVsHierarchy[1];
while (0 == ppEnum.Next(1, nodes, out actualResult))
{
Object obj;
nodes[0].GetProperty((uint)Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT, (int)Microsoft.VisualStudio.Shell.Interop.__VSHPROPID.VSHPROPID_ExtObject, out obj);
Project project = obj as Project;
if (project != null)
{
if (string.IsNullOrEmpty(projectKind))
{
projects.Add(project);
}
else if (projectKind.Equals(project.Kind, StringComparison.InvariantCultureIgnoreCase))
{
projects.Add(project);
}
}
}
}
return projects.ToArray();
}
示例3: EnumerateLoadedProjects
private static IEnumerable<IVsProject> EnumerateLoadedProjects(IVsSolution solution) {
var guid = new Guid(PythonConstants.ProjectFactoryGuid);
IEnumHierarchies hierarchies;
ErrorHandler.ThrowOnFailure((solution.GetProjectEnum(
(uint)(__VSENUMPROJFLAGS.EPF_MATCHTYPE | __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION),
ref guid,
out hierarchies)));
IVsHierarchy[] hierarchy = new IVsHierarchy[1];
uint fetched;
while (ErrorHandler.Succeeded(hierarchies.Next(1, hierarchy, out fetched)) && fetched == 1) {
var project = hierarchy[0] as IVsProject;
if (project != null) {
yield return project;
}
}
}
示例4: ProjectsInSolution
public static IEnumerable<IVsProject> ProjectsInSolution(IVsSolution solution)
{
IEnumHierarchies enumerator;
var guid = Guid.Empty;
solution.GetProjectEnum((uint) __VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref guid, out enumerator);
var hierarchy = new IVsHierarchy[] {null};
uint fetched;
for (enumerator.Reset();
enumerator.Next(1, hierarchy, out fetched) == VSConstants.S_OK && fetched == 1;
/*nothing*/)
{
yield return (IVsProject) hierarchy[0];
}
}
示例5: GetProjectsInSolution
private static IEnumerable<IVsHierarchy> GetProjectsInSolution(IVsSolution solution)
{
if (solution == null) throw new ArgumentNullException("solution");
IEnumHierarchies enumHierarchies;
var guid = Guid.Empty;
solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref guid, out enumHierarchies);
// Invalid result?
if (enumHierarchies == null)
yield break;
var hierarchyArray = new IVsHierarchy[1];
uint hierarchyFetched;
// Fetch one by one
while (enumHierarchies.Next(1, hierarchyArray, out hierarchyFetched) == VSConstants.S_OK && hierarchyFetched == 1)
{
if (hierarchyArray[0] != null)
yield return hierarchyArray[0];
}
}
示例6: GetProjectAndFileInfoForPath
private static void GetProjectAndFileInfoForPath(
string originalPath, IServiceProvider serviceProvider, IVsSolution solution, out IVsHierarchy projectHierarchy,
out Project project, out uint fileItemId, out bool isDocumentInProject) {
var guid = Guid.Empty;
IEnumHierarchies hierarchyEnum = null;
fileItemId = VSConstants.VSITEMID_NIL;
projectHierarchy = null;
isDocumentInProject = false;
project = null;
if (solution != null) {
var hr = solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_ALLPROJECTS, ref guid, out hierarchyEnum);
if (NativeMethods.Succeeded(hr) && hierarchyEnum != null) {
hierarchyEnum.Reset();
uint numFetched = 1;
var item = new IVsHierarchy[1];
hierarchyEnum.Next(1, item, out numFetched);
while (numFetched == 1) {
var vsProject = item[0] as IVsProject;
if (vsProject != null) {
GetProjectAndFileInfoForPath(
vsProject, originalPath, out projectHierarchy, out project, out fileItemId, out isDocumentInProject);
if (isDocumentInProject) {
break;
}
}
hierarchyEnum.Next(1, item, out numFetched);
}
}
}
// didn't find a project, so check the misc files project
if (project == null) {
//
// try not to create the Misc files project externally - in some rare cases it has caused Access violoations in VS (e.g., Dev10 Bug 864725).
// So, only create this if we really need it.
//
IVsProject3 miscFilesProject = null;
if (serviceProvider == null) {
miscFilesProject = GetMiscellaneousProject();
} else {
miscFilesProject = GetMiscellaneousProject(serviceProvider);
}
if (miscFilesProject != null) {
GetProjectAndFileInfoForPath(
miscFilesProject, originalPath, out projectHierarchy, out project, out fileItemId, out isDocumentInProject);
if (project == null) {
projectHierarchy = miscFilesProject as IVsHierarchy;
if (projectHierarchy != null) {
project = GetProject(projectHierarchy);
}
}
}
}
}
示例7: EnumerateProjects
private static IEnumerable<IVsHierarchy> EnumerateProjects(IVsSolution solution)
{
Guid empty = Guid.Empty;
IEnumHierarchies projectsEnum;
ErrorHandler.ThrowOnFailure(solution.GetProjectEnum((uint)__VSENUMPROJFLAGS.EPF_LOADEDINSOLUTION, ref empty, out projectsEnum));
IVsHierarchy[] output = new IVsHierarchy[1];
uint fetched;
while (ErrorHandler.Succeeded(projectsEnum.Next(1, output, out fetched)) && fetched == 1)
{
yield return output[0];
}
}
示例8: GetProjectsInSolution
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];
}
}