Utils.List |
Lists to hierarchy in order to be able to insert it by parents first.
Namespace: Gamanet.C4.SimpleInterfaces
Assembly: Gamanet.C4.SimpleInterfaces (in Gamanet.C4.SimpleInterfaces.dll) Version: 2026.0.0.242
Syntax
C#
public static IList<TreeNode<T>> ListToHierarchy<T>( IList<T> list ) where T : ISimpleEntity
Parameters
- list IList<T>
- The list.
Type Parameters
- T
- simple entity
Return Value
IList<TreeNode<T>>Hierarchy tree
Example
The following example illustrates how Utils converts entities list to entities hierarchy.
C#
using System; using Gamanet.C4.SDK; using Gamanet.C4.SimpleInterfaces; public class UtilsSortHierarchyByParents { static void Main() { // create instance of simple client var client = new SimpleClient(ConnectorConfiguration.RestClient, null); string token; // connect to file connector var connectionResult = client.Connect(new Uri("https://localhost/"), "Support", "support123", out token); if (connectionResult != ConnectionResult.Successful) { Console.WriteLine("Connection unSuccessful, result: {0}", connectionResult); return; } Console.WriteLine("Connection result: {0}", connectionResult); Console.WriteLine(); // load all persons var persons = client.Persons.GetAll(); SimplePerson superRoot = null; foreach (var person in persons) { if (person.Id == EntityRoot.PersonSuperRoot) { superRoot = person; } } // remove the super root. As a result, there are now 3 separate roots (PersonRoot, GroupRoot, RoleRoot). These were directly under the super root. persons.Remove(superRoot); // create tree node structures based on multiple roots, // you can use it with hierarchical entities (SimplePerson, SimpleDevice, SimpleRegion) var treeNodeRoots = Utils.ListToHierarchy(persons); // create hierarchy from tree node root structures var personsTree = Utils.SortHierarchyByParents(treeNodeRoots); // display persons tree foreach (var person in personsTree) { Console.WriteLine(person.Name); } // disconnect from server client.Disconnect(); // The example displays the following output: // Connection result: Successful // root // Support // RolesRoot // Manager // Reception // Administrator // Support // Dispatcher // Service Technician // Group Root } }
See Also