Utils.GetSubtree<T>(TreeNode<T>) Method

Sorts the tree by parents 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<T> GetSubtree<T>(
	TreeNode<T> root
)
where T : ISimpleEntity

Parameters

root  TreeNode<T>
The root.

Type Parameters

T
simple entity

Return Value

IList<T>
Sorted tree list by parents
Example
The following example illustrates how Utils converts entities list to entities tree.
C#
using System;
using Gamanet.C4.SDK;
using Gamanet.C4.SimpleInterfaces;

public class UtilsGetSubtree
{
    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();

        // create tree node structure, you can use it with hierarchical entities (SimplePerson, SimpleDevice, SimpleRegion) 
        var treeNodeRoot = Utils.ListToTree(persons);

        // get subtree from tree node root structure
        var personsTree = Utils.GetSubtree(treeNodeRoot);

        // 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

        // PersonSuperRoot
        // root
        // Support
        // RolesRoot
        // Manager
        // Reception
        // Administrator
        // Support
        // Dispatcher
        // Service Technician
        // Group Root
    }
}
See Also

Reference

Utils Class
GetSubtree Overload
Gamanet.C4.SimpleInterfaces Namespace