当前位置: 首页>>代码示例>>C#>>正文


C# IVsHierarchy.GetNestedHierarchy方法代码示例

本文整理汇总了C#中IVsHierarchy.GetNestedHierarchy方法的典型用法代码示例。如果您正苦于以下问题:C# IVsHierarchy.GetNestedHierarchy方法的具体用法?C# IVsHierarchy.GetNestedHierarchy怎么用?C# IVsHierarchy.GetNestedHierarchy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IVsHierarchy的用法示例。


在下文中一共展示了IVsHierarchy.GetNestedHierarchy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VsSolutionHierarchyNode

      internal VsSolutionHierarchyNode(IVsHierarchy hierarchy, uint itemId, Lazy<VsSolutionHierarchyNode> parent)
      {
         if (hierarchy == null)
            throw new ArgumentNullException(nameof(hierarchy), $"{nameof(hierarchy)} is null.");

         VsHierarchy = hierarchy;
         ItemId = itemId;

         IntPtr nestedHierarchyObj;
         uint nestedItemId;
         Guid hierGuid = typeof(IVsHierarchy).GUID;

         // Check first if this node has a nested hierarchy. If so, then there really are two 
         // identities for this node: 1. hierarchy/itemid 2. nestedHierarchy/nestedItemId.
         // We will recurse and call EnumHierarchyItems which will display this node using
         // the inner nestedHierarchy/nestedItemId identity.
         int hr = hierarchy.GetNestedHierarchy(itemId, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
         if (hr == VSConstants.S_OK && nestedHierarchyObj != IntPtr.Zero)
         {
            IVsHierarchy nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy;
            Marshal.Release(nestedHierarchyObj); // we are responsible to release the refcount on the out IntPtr parameter
            if (nestedHierarchy != null)
            {
               VsHierarchy = nestedHierarchy;
               ItemId = nestedItemId;
            }
         }
                  
         DisplayName = VsHierarchy.GetProperty<string>(__VSHPROPID.VSHPROPID_Name, ItemId);

         m_parent = parent ?? new Lazy<VsSolutionHierarchyNode>(() =>
         {
            if (VsHierarchy is IVsSolution)
               return null;

            var rootHierarchy = hierarchy.GetProperty<IVsHierarchy>(__VSHPROPID.VSHPROPID_ParentHierarchy, VSConstants.VSITEMID_ROOT);
            if (rootHierarchy == null)
               return null;

            var rootNode = new VsSolutionHierarchyNode(rootHierarchy, VSConstants.VSITEMID_ROOT);

            var parentNode = new VsSolutionHierarchyNode[] { rootNode }
                .Concat(rootNode.Children.BreadthFirstTraversal(node => node.Children))
                .FirstOrDefault(node => node.Children.Any(child => child.ItemId == ItemId));

            if (parentNode == null)
               return null;

            return new VsSolutionHierarchyNode(parentNode.VsHierarchy, parentNode.ItemId);
         });

         this.m_serviceProvider = new Lazy<IServiceProvider>(() =>
         {
            Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp;
            hierarchy.GetSite(out oleSp);
            return oleSp != null ?
                new ServiceProvider(oleSp) :
                GlobalVsServiceProvider.Instance;
         });
      }
开发者ID:modulexcite,项目名称:AlphaVSX,代码行数:60,代码来源:VsSolutionHierarchyNode.cs

示例2: CollapseHierarchyItems

 private void CollapseHierarchyItems(IVsUIHierarchyWindow toolWindow, IVsHierarchy hierarchy, uint itemid, bool hierIsSolution
     , string[] captions)
 {
     IntPtr ptr;
     uint num2;
     Guid gUID = typeof(IVsHierarchy).GUID;
     if ((hierarchy.GetNestedHierarchy(itemid, ref gUID, out ptr, out num2) == 0) && (IntPtr.Zero != ptr))
     {
         IVsHierarchy objectForIUnknown = Marshal.GetObjectForIUnknown(ptr) as IVsHierarchy;
         Marshal.Release(ptr);
         if (objectForIUnknown != null)
         {
             this.CollapseHierarchyItems(toolWindow, objectForIUnknown, num2, false, captions);
         }
     }
     else
     {
         object obj2;
         if (!hierIsSolution)
         {
             string canonicalname;
             object captionobj;
             hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_Caption, out captionobj);
             var caption = (string)captionobj;
             if (captions.Contains(caption))
             {
                 hierarchy.GetCanonicalName(itemid, out canonicalname);
                 ErrorHandler.ThrowOnFailure(toolWindow.ExpandItem(hierarchy as IVsUIHierarchy, itemid, EXPANDFLAGS.EXPF_CollapseFolder));
             }
         }
         if (hierarchy.GetProperty(itemid, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out obj2) == 0)
         {
             uint itemId = this.GetItemId(obj2);
             while (itemId != uint.MaxValue)
             {
                 this.CollapseHierarchyItems(toolWindow, hierarchy, itemId, false, captions);
                 int hr = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out obj2);
                 if (hr == 0)
                 {
                     itemId = this.GetItemId(obj2);
                 }
                 else
                 {
                     ErrorHandler.ThrowOnFailure(hr);
                     return;
                 }
             }
         }
     }
 }
开发者ID:slamj1,项目名称:ServiceMatrix,代码行数:50,代码来源:CollapseFoldersCommand.cs

示例3: VsSolutionHierarchyNode

        internal VsSolutionHierarchyNode(IVsHierarchy hierarchy, uint itemId, Lazy<VsSolutionHierarchyNode> parent)
        {
            Guard.NotNull(() => hierarchy, hierarchy);

            this.VsHierarchy = hierarchy;
            this.ItemId = itemId;

            IntPtr nestedHierarchyObj;
            uint nestedItemId;
            Guid hierGuid = typeof(IVsHierarchy).GUID;

            int hr = hierarchy.GetNestedHierarchy(this.ItemId, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
            if (hr == VSConstants.S_OK && nestedHierarchyObj != IntPtr.Zero)
            {
                IVsHierarchy nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy;
                Marshal.Release(nestedHierarchyObj);
                if (nestedHierarchy != null)
                {
                    this.VsHierarchy = nestedHierarchy;
                    this.ItemId = nestedItemId;
                }
            }

            this.extensibilityObject = new Lazy<object>(() => this.VsHierarchy.Properties(this.ItemId).ExtenderObject);
            this.serviceProvider = new Lazy<IServiceProvider>(() =>
            {
                Microsoft.VisualStudio.OLE.Interop.IServiceProvider oleSp;
                hierarchy.GetSite(out oleSp);
                return oleSp != null ?
                    new ServiceProvider(oleSp) :
                    GlobalServiceProvider.Instance;
            });

            this.DisplayName = this.VsHierarchy.Properties(this.ItemId).DisplayName;
            this.parent = parent ?? new Lazy<VsSolutionHierarchyNode>(() =>
            {
                if (this.VsHierarchy is IVsSolution)
                    return null;

                // Implement this property so that it iterates each and every node finding 
                // the parent.
				var parentItem = this.VsHierarchy.Properties(this.ItemId).Parent;
				if (parentItem == null)
					return null;

				return new VsSolutionHierarchyNode(parentItem.Hierarchy, parentItem.ItemId);
            });
        }
开发者ID:MobileEssentials,项目名称:clide,代码行数:48,代码来源:VsSolutionHierarchyNode.cs

示例4: EnumHierarchyItems

        /// <summary>
        /// Enumerates over the hierarchy items for the given hierarchy traversing into nested hierarchies.
        /// </summary>
        /// <param name="hierarchy">hierarchy to enmerate over.</param>
        /// <param name="itemid">item id of the hierarchy</param>
        /// <param name="recursionLevel">Depth of recursion. e.g. if recursion started with the Solution
        /// node, then : Level 0 -- Solution node, Level 1 -- children of Solution, etc.</param>
        /// <param name="hierIsSolution">true if hierarchy is Solution Node. This is needed to special
        /// case the children of the solution to work around a bug with VSHPROPID_FirstChild and 
        /// VSHPROPID_NextSibling implementation of the Solution.</param>
        /// <param name="visibleNodesOnly">true if only nodes visible in the Solution Explorer should
        /// be traversed. false if all project items should be traversed.</param>
        /// <param name="processNodeFunc">pointer to function that should be processed on each
        /// node as it is visited in the depth first enumeration.</param>
        private void EnumHierarchyItems(IVsHierarchy hierarchy, uint itemid, int recursionLevel, bool hierIsSolution, bool visibleNodesOnly)
        {
            int hr;
            IntPtr nestedHierarchyObj;
            uint nestedItemId;
            Guid hierGuid = typeof(IVsHierarchy).GUID;

            // Check first if this node has a nested hierarchy. If so, then there really are two
            // identities for this node: 1. hierarchy/itemid 2. nestedHierarchy/nestedItemId.
            // We will recurse and call EnumHierarchyItems which will display this node using
            // the inner nestedHierarchy/nestedItemId identity.
            hr = hierarchy.GetNestedHierarchy(itemid, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
            if (VSConstants.S_OK == hr && IntPtr.Zero != nestedHierarchyObj)
            {
                IVsHierarchy nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy;
                Marshal.Release(nestedHierarchyObj);    // we are responsible to release the refcount on the out IntPtr parameter
                if (nestedHierarchy != null)
                {
                    // Display name and type of the node in the Output Window
                    EnumHierarchyItems(nestedHierarchy, nestedItemId, recursionLevel, false, visibleNodesOnly);
                }
            }
            else
            {
                object pVar;

                // Display name and type of the node in the Output Window
                ProcessSolutionNode(hierarchy, itemid, recursionLevel);

                recursionLevel++;

                //Get the first child node of the current hierarchy being walked
                // NOTE: to work around a bug with the Solution implementation of VSHPROPID_FirstChild,
                // we keep track of the recursion level. If we are asking for the first child under
                // the Solution, we use VSHPROPID_FirstVisibleChild instead of _FirstChild.
                // In VS 2005 and earlier, the Solution improperly enumerates all nested projects
                // in the Solution (at any depth) as if they are immediate children of the Solution.
                // Its implementation _FirstVisibleChild is correct however, and given that there is
                // not a feature to hide a SolutionFolder or a Project, thus _FirstVisibleChild is
                // expected to return the identical results as _FirstChild.
                hr = hierarchy.GetProperty(itemid,
                    ((visibleNodesOnly || (hierIsSolution && recursionLevel == 1) ?
                        (int)__VSHPROPID.VSHPROPID_FirstVisibleChild : (int)__VSHPROPID.VSHPROPID_FirstChild)),
                    out pVar);
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr);
                if (VSConstants.S_OK == hr)
                {
                    //We are using Depth first search so at each level we recurse to check if the node has any children
                    // and then look for siblings.
                    uint childId = GetItemId(pVar);
                    while (childId != VSConstants.VSITEMID_NIL)
                    {
                        EnumHierarchyItems(hierarchy, childId, recursionLevel, false, visibleNodesOnly);
                        // NOTE: to work around a bug with the Solution implementation of VSHPROPID_NextSibling,
                        // we keep track of the recursion level. If we are asking for the next sibling under
                        // the Solution, we use VSHPROPID_NextVisibleSibling instead of _NextSibling.
                        // In VS 2005 and earlier, the Solution improperly enumerates all nested projects
                        // in the Solution (at any depth) as if they are immediate children of the Solution.
                        // Its implementation   _NextVisibleSibling is correct however, and given that there is
                        // not a feature to hide a SolutionFolder or a Project, thus _NextVisibleSibling is
                        // expected to return the identical results as _NextSibling.
                        hr = hierarchy.GetProperty(childId,
                            ((visibleNodesOnly || (hierIsSolution && recursionLevel == 1)) ?
                                (int)__VSHPROPID.VSHPROPID_NextVisibleSibling : (int)__VSHPROPID.VSHPROPID_NextSibling),
                            out pVar);
                        if (VSConstants.S_OK == hr)
                        {
                            childId = GetItemId(pVar);
                        }
                        else
                        {
                            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hr);
                            break;
                        }
                    }
                }
            }
        }
开发者ID:gramcha,项目名称:XFeatures,代码行数:92,代码来源:SolutionReader.cs

示例5: ProcessHierarchyNodeRecursively

        /// <summary>
        /// Process all project hierarchy nodes recursively returning information about the files in them
        /// </summary>
        /// <param name="hierarchy">The starting hierarchy node</param>
        /// <param name="itemId">The item ID</param>
        /// <param name="projectFiles">The list to which project file information is added</param>
        private static void ProcessHierarchyNodeRecursively(IVsHierarchy hierarchy, uint itemId,
          IList<SpellCheckFileInfo> projectFiles)
        {
            int result;
            IntPtr nestedHiearchyValue = IntPtr.Zero;
            uint nestedItemIdValue = 0;
            object value = null;
            uint visibleChildNode;
            Guid nestedHierarchyGuid;
            IVsHierarchy nestedHierarchy;

            // First, guess if the node is actually the root of another hierarchy (a project, for example)
            nestedHierarchyGuid = typeof(IVsHierarchy).GUID;
            result = hierarchy.GetNestedHierarchy(itemId, ref nestedHierarchyGuid, out nestedHiearchyValue, out nestedItemIdValue);

            if(result == VSConstants.S_OK && nestedHiearchyValue != IntPtr.Zero && nestedItemIdValue == VSConstants.VSITEMID_ROOT)
            {
                // Get the new hierarchy
                nestedHierarchy = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(nestedHiearchyValue) as IVsHierarchy;
                System.Runtime.InteropServices.Marshal.Release(nestedHiearchyValue);

                if(nestedHierarchy != null)
                    ProcessHierarchyNodeRecursively(nestedHierarchy, VSConstants.VSITEMID_ROOT, projectFiles);
            }
            else
            {
                // The node is not the root of another hierarchy, it is a regular node
                var projectFile = DetermineProjectFileInformation(hierarchy, itemId);

                if(projectFile != null)
                    projectFiles.Add(projectFile);

                result = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out value);

                while(result == VSConstants.S_OK && value != null && value is int)
                {
                    visibleChildNode = (uint)(int)value;

                    if(visibleChildNode == VSConstants.VSITEMID_NIL)
                        break;

                    ProcessHierarchyNodeRecursively(hierarchy, visibleChildNode, projectFiles);

                    value = null;
                    result = hierarchy.GetProperty(visibleChildNode, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out value);
                }
            }
        }
开发者ID:kazu46,项目名称:VSSpellChecker,代码行数:54,代码来源:SpellCheckFileInfo.cs

示例6: TraverseHierarchyItem

        // --------------------------------------------------------------------------------------------
        /// <summary>
        /// Enumerates over the hierarchy items for the given hierarchy traversing into nested
        /// hierarchies.
        /// </summary>
        /// <param name="hierarchy">Hierarchy to enumerate over.</param>
        /// <param name="itemid">Item id of the hierarchy item to start traversal from.</param>
        /// <param name="recursionLevel">Depth of recursion. e.g. if recursion started with the Solution
        /// node, then : Level 0 -- Solution node, Level 1 -- children of Solution, etc.</param>
        /// <param name="hierIsSolution">true if hierarchy is Solution Node. This is needed to special
        /// case the children of the solution to work around a bug with VSHPROPID_FirstChild and
        /// VSHPROPID_NextSibling implementation of the Solution.</param>
        /// <returns></returns>
        // --------------------------------------------------------------------------------------------
        private static IEnumerable<HierarchyTraversalInfo> TraverseHierarchyItem(
            IVsHierarchy hierarchy,
            uint itemid,
            int recursionLevel,
            bool hierIsSolution)
        {
            IntPtr nestedHierarchyObj;
              uint nestedItemId;
              var hierGuid = typeof(IVsHierarchy).GUID;

              // Check first if this node has a nested hierarchy. If so, then there really are two
              // identities for this node: 1. hierarchy/itemid 2. nestedHierarchy/nestedItemId.
              // We will recurse and call EnumHierarchyItems which will display this node using
              // the inner nestedHierarchy/nestedItemId identity.
              var hr = hierarchy.GetNestedHierarchy(itemid, ref hierGuid, out nestedHierarchyObj, out nestedItemId);
              if (VSConstants.S_OK == hr && IntPtr.Zero != nestedHierarchyObj)
              {
            var nestedHierarchy = Marshal.GetObjectForIUnknown(nestedHierarchyObj) as IVsHierarchy;
            Marshal.Release(nestedHierarchyObj); // we are responsible to release the refcount on the out IntPtr parameter
            if (nestedHierarchy != null)
            {
              foreach (var item in TraverseHierarchyItem(nestedHierarchy, nestedItemId, recursionLevel, false))
              {
            yield return item;
              }
            }
              }
              else
              {
            // --- Return the current hierarchy item
            yield return new HierarchyTraversalInfo(hierarchy, itemid, recursionLevel);
            recursionLevel++;

            // --- Get the first child node of the current hierarchy being walked.
            // --- NOTE: to work around a bug with the Solution implementation of VSHPROPID_FirstChild,
            // --- we keep track of the recursion level. If we are asking for the first child under
            // --- the Solution, we use VSHPROPID_FirstVisibleChild instead of _FirstChild.
            // --- In VS 2005 and earlier, the Solution improperly enumerates all nested projects
            // --- in the Solution (at any depth) as if they are immediate children of the Solution.
            // --- Its implementation _FirstVisibleChild is correct however, and given that there is
            // --- not a feature to hide a SolutionFolder or a Project, thus _FirstVisibleChild is
            // --- expected to return the identical results as _FirstChild.
            object pVar;
            hr = hierarchy.GetProperty(itemid,
                                   (hierIsSolution && recursionLevel == 1)
                                     ? (int) __VSHPROPID.VSHPROPID_FirstVisibleChild
                                     : (int) __VSHPROPID.VSHPROPID_FirstChild,
                                   out pVar);
            ErrorHandler.ThrowOnFailure(hr);
            if (VSConstants.S_OK == hr)
            {
              // --- We are using DFS so at each level we recurse to check if the node has any
              // --- children and then look for siblings.
              var childId = GetItemId(pVar);
              while (childId != VSConstants.VSITEMID_NIL)
              {
            foreach (var item in TraverseHierarchyItem(hierarchy, childId, recursionLevel, false))
            {
              yield return item;
            }
            // --- NOTE: to work around a bug with the Solution implementation of VSHPROPID_NextSibling,
            // --- we keep track of the recursion level. If we are asking for the next sibling under
            // --- the Solution, we use VSHPROPID_NextVisibleSibling instead of _NextSibling.
            // --- In VS 2005 and earlier, the Solution improperly enumerates all nested projects
            // --- in the Solution (at any depth) as if they are immediate children of the Solution.
            // --- Its implementation   _NextVisibleSibling is correct however, and given that there is
            // --- not a feature to hide a SolutionFolder or a Project, thus _NextVisibleSibling is
            // --- expected to return the identical results as _NextSibling.
            hr = hierarchy.GetProperty(childId,
                                       (hierIsSolution && recursionLevel == 1)
                                         ? (int)__VSHPROPID.VSHPROPID_NextVisibleSibling
                                         : (int)__VSHPROPID.VSHPROPID_NextSibling,
                                       out pVar);
            if (VSConstants.S_OK == hr)
            {
              childId = GetItemId(pVar);
            }
            else
            {
              ErrorHandler.ThrowOnFailure(hr);
              break;
            }
              }
            }
              }
        }
开发者ID:sunpander,项目名称:VSDT,代码行数:100,代码来源:Solution.cs

示例7: ProcessHierarchyNodeRecursively

    static void ProcessHierarchyNodeRecursively(IVsHierarchy hierarchy, uint itemId) {
      int result;
      IntPtr nestedHiearchyValue = IntPtr.Zero;
      uint nestedItemIdValue = 0;
      object value = null;
      uint visibleChildNode;
      Guid nestedHierarchyGuid;
      IVsHierarchy nestedHierarchy;

      // First, guess if the node is actually the root of another hierarchy (a project, for example)
      nestedHierarchyGuid = typeof(IVsHierarchy).GUID;
      result = hierarchy.GetNestedHierarchy(itemId, ref nestedHierarchyGuid, out nestedHiearchyValue, out nestedItemIdValue);

      if (result == VSConstants.S_OK && nestedHiearchyValue != IntPtr.Zero && nestedItemIdValue == VSConstants.VSITEMID_ROOT) {
        // Get the new hierarchy
        nestedHierarchy = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(nestedHiearchyValue) as IVsHierarchy;
        System.Runtime.InteropServices.Marshal.Release(nestedHiearchyValue);

        if (nestedHierarchy != null) {
          ProcessHierarchy(nestedHierarchy);
        }
      } else // The node is not the root of another hierarchy, it is a regular node
         {
        ShowNodeName(hierarchy, itemId);

        // Get the first visible child node
        result = hierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_FirstVisibleChild, out value);

        while (result == VSConstants.S_OK && value != null) {
          if (value is int && (uint)(int)value == VSConstants.VSITEMID_NIL) {
            // No more nodes
            break;
          } else {
            visibleChildNode = Convert.ToUInt32(value);

            // Enter in recursion
            ProcessHierarchyNodeRecursively(hierarchy, visibleChildNode);

            // Get the next visible sibling node
            value = null;
            result = hierarchy.GetProperty(visibleChildNode, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out value);
          }
        }
      }
    }
开发者ID:PavelPZ,项目名称:REW,代码行数:45,代码来源:SolutionToolbarPackage.cs


注:本文中的IVsHierarchy.GetNestedHierarchy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。