C # hierarchy library library? - anyone knows one (e.g. GetDirectChildren, GetAllChildren, GetParent)

Does anyone know of a solid C # library / approach for managing a collection of hierarchy types / web pages?

This will be a library that will consist of the concept of nodes and relationships, for example, for modeling web pages / files linked by URL, or for modeling IT infrastructure. It will have key methods such as:

  • Node.GetDirectParents ()

  • Node.GetRootParents ()

  • Node.GetDirectChildren ()

  • Node.GetAllChildren ()

Thus, smarts will include the ability to “walk the tree” of nodes based on relationships, when someone asks “give me all the children under this node,” for example.

Ideally, it includes a save layer to save / retrieve such data to / from databases (for example, using the Nodes and Relationships tables).

EDIT 1

  • Also note that it must support full open flexibility, that there are nodes and relationships, and therefore, a node can be a child of more than one node. That is, it can model more web maps, as opposed to a strict hierarchy.
  • In addition, a node can have more than one root / parent of a node (for example, in the case of modeling web page artifacts, an image can be referenced on several websites).
+3
source share
4 answers

QuickGraph is the closest thing I've found so far ...

http://quickgraph.codeplex.com/

+1
source

, self, "Parent" "Children". : , , "", 'this' "" .

.

   public class Whatever
   {
      public Whatever Parent {get; private set;}
      protected List<Whatever> Children {get; private set;}


      public Whatever(Whatever parent)
      {
          this.parent = parent;
          this.Children = new List<Whatever>();
          if (parent != null)
          {
              parent.Children.Add(this);
          }
      }

      public IEnumerable<Whatever> AllChildren
      {
         return this.Children.Union(this.Children.SelectMany(child => child.AllChildren));
      }

With this in place AllChildren, DirectChildren, Root are easily implemented.

When you serialize the database, you only need to write the ParentID for each instance and restore it after loading. node without a parent is the root.

0
source

Source: https://habr.com/ru/post/1742738/


All Articles