Utils.FindNode<T> Method

Finds the node by entity Id.

Namespace: Gamanet.C4.SimpleInterfaces
Assembly: Gamanet.C4.SimpleInterfaces (in Gamanet.C4.SimpleInterfaces.dll) Version: 2026.0.0.242
Syntax
C#
public static TreeNode<T> FindNode<T>(
	TreeNode<T> root,
	Guid idToFind
)
where T : ISimpleEntity

Parameters

root  TreeNode<T>
The root.
idToFind  Guid
The identifier to find.

Type Parameters

T
simple entity

Return Value

TreeNode<T>
node
Example
The following example illustrates how Utils find node.
C#
using System;
using Gamanet.C4.SimpleInterfaces;

public class UtilsGetSubtreeByRootId
{
    static void Main()
    {
        // creating tree of persons for example
        var personTree = new List<SimplePerson>
        {
            // root
            new SimplePerson(Guid.Parse("77464B5A-8502-4ABB-905D-8745BDCAD8D0"), "Root",
                Guid.Empty, Guid.Parse("81eb624e-c2b3-4b75-8e77-a65a859edbda")),
            // support
            new SimplePerson(Guid.Parse("02EF880C-5C58-468D-85A9-5BF0D3716C05"), "Support",
                Guid.Parse("77464B5A-8502-4ABB-905D-8745BDCAD8D0"),
                Guid("5fefa0a9-70ee-46aa-bbbd-bed5888c445c")),
            // company under root
            new SimplePerson(Guid.Parse("49ED8DA6-8448-4E52-8CE5-386E382E66B8"), "Company B",
                Guid.Parse("77464B5A-8502-4ABB-905D-8745BDCAD8D0"),
                Guid.Parse("47336057-7ecb-4d0b-9e82-48be62556d95")),
            // child for company 1
            new SimplePerson(Guid.Parse("3F2071C8-8AE1-4AD7-A30E-88EB1C21E995"), "Robert",
                Guid.Parse("49ED8DA6-8448-4E52-8CE5-386E382E66B8"),
                Guid("5fefa0a9-70ee-46aa-bbbd-bed5888c445c")),
            // child for company 2
            new SimplePerson(Guid.Parse("ACAA7D62-CAE1-4DC0-BE87-3C08037818B5"), "Josef",
                Guid.Parse("49ED8DA6-8448-4E52-8CE5-386E382E66B8"),
                Guid("5fefa0a9-70ee-46aa-bbbd-bed5888c445c"))
        };

        // convert list to tree structure with one root 
        var rootTree = Utils.ListToTree(personTree.Cast<SimpleEntity>().ToList());

        // our entity to find node
        var company = personTree.FirstOrDefault(p => p.Name == "Company B");

        Console.WriteLine("Expected entity properties:");
        Console.WriteLine($"ID : {company.Id}");
        Console.WriteLine($"Name : {company.Name}");
        Console.WriteLine($"ParentId : {company.ParentId}");
        Console.WriteLine($"CategoryId : {company.CategoryId}");

        // find node by method
        var node = Utils.FindNode(rootTree, company.Id);

        // entity from node
        var companyFromNode = (SimplePerson)node.Node;

        Console.WriteLine("\nFound node entity properties:");
        Console.WriteLine($"ID : {companyFromNode.Id}");
        Console.WriteLine($"Name : {companyFromNode.Name}");
        Console.WriteLine($"ParentId : {companyFromNode.ParentId}");
        Console.WriteLine($"CategoryId : {companyFromNode.CategoryId}");

        // The example displays the following output:
        Expected entity properties:
        ID : 49ED8DA6-8448-4E52-8CE5-386E382E66B8
        Name : Company B
        ParentId : 77464B5A-8502-4ABB-905D-8745BDCAD8D0
        CategoryId : 47336057-7ecb-4d0b-9e82-48be62556d95

        Found node entity properties:
        ID : 49ED8DA6-8448-4E52-8CE5-386E382E66B8
        Name : Company B
        ParentId : 77464B5A-8502-4ABB-905D-8745BDCAD8D0
        CategoryId : 47336057-7ecb-4d0b-9e82-48be62556d95
    }
}
See Also

Reference

Utils Class
Gamanet.C4.SimpleInterfaces Namespace