Table of Contents

Class HierarchySerializer

Namespace
Cuemon.Extensions.Runtime.Serialization
Assembly
Cuemon.Extensions.Core.dll

Provides a way to serialize objects to nodes of IHierarchy<T>.

public class HierarchySerializer
Inheritance
HierarchySerializer
Extension Methods

Examples

HierarchySerializer converts any object graph into a hierarchical node structure (IHierarchy<DataPair>) for inspection and path-based representation. This example creates a ReportRoot with a Name of "alpha" and a ReportChild with Count = 7, passes it to the HierarchySerializer constructor, and accesses the root node's instance type name, checks whether it has children, and prints the tree path representation via ToString(). Key steps include constructing a serializer from a plain object and reading the resulting node properties. Console output displays the ReportRoot type name, True for HasChildren, and a path-based tree showing ReportRoot > ReportChild.

using System;
using Cuemon.Extensions.Runtime.Serialization;

namespace MyApp.Examples;

public static class HierarchySerializerExample
{
    private sealed class ReportRoot
    {
        public string Name { get; set; } = string.Empty;

        public ReportChild Child { get; set; } = new ReportChild();
    }

    private sealed class ReportChild
    {
        public int Count { get; set; }
    }

    public static void Demonstrate()
    {
        var serializer = new HierarchySerializer(new ReportRoot
        {
            Name = "alpha",
            Child = new ReportChild { Count = 7 }
        });

        Console.WriteLine(serializer.Nodes.InstanceType.Name);
        Console.WriteLine(serializer.Nodes.HasChildren);
        Console.WriteLine(serializer.ToString());
    }
}

Constructors

HierarchySerializer(object, Action<HierarchyOptions>)

Initializes a new instance of the HierarchySerializer class.

public HierarchySerializer(object source, Action<HierarchyOptions> setup = null)

Parameters

source object

The object to convert to nodes of IHierarchy<T>.

setup Action<HierarchyOptions>

The HierarchyOptions which need to be configured.

Properties

Nodes

Gets the result of the IHierarchy<T>.

public IHierarchy<object> Nodes { get; }

Property Value

IHierarchy<object>

The converted nodes of the by constructor defined source object.

Methods

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.