Table of Contents

Class HierarchyOptions

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

Specifies options that is related to Hierarchy and HierarchySerializer operations.

public class HierarchyOptions : IParameterObject
Inheritance
HierarchyOptions
Implements
Extension Methods

Examples

The following example demonstrates how to configure to control the depth of object hierarchy traversal and skip specific property types.

using System;
using System.Linq;
using Cuemon.Extensions.Runtime;

namespace MyApp.Examples;

public class HierarchyOptionsExample
{
    public void Demonstrate()
    {
        // Direct instantiation of HierarchyOptions
        var hierarchyOptions = new HierarchyOptions
        {
            MaxDepth = 2,
            SkipPropertyType = t => t == typeof(string) || t.IsValueType
        };

        var source = new
        {
            Name = "Root",
            Value = 42,
            Nested = new
            {
                Deep = new
                {
                    Deeper = "found"
                }
            }
        };

        // Limit depth to 2 and skip string types
        var hierarchy = Hierarchy.GetObjectHierarchy(source, o =>
        {
            o.MaxDepth = 2;
            o.SkipPropertyType = t => t == typeof(string) || t.IsValueType;
        });

        var root = hierarchy;
        Console.WriteLine($"Root type: {root.InstanceType.Name}"); // Anonymous type

        var children = root.GetChildren().ToList();
        Console.WriteLine($"Children count: {children.Count}"); // 0 (all primitive types skipped)
    }
}

Constructors

HierarchyOptions()

Initializes a new instance of the HierarchyOptions class.

public HierarchyOptions()

Properties

HasCircularReference

Gets or sets the function delegate that is invoked when a property has a value and whose return value suggest a circular reference.

public Func<object, bool> HasCircularReference { get; set; }

Property Value

Func<object, bool>

A Func<TResult> that determines if an object is suggesting a circular reference.

MaxCircularCalls

Gets or sets the maximum amount of times an object is allowed to make circular calls. Default is 2.

public int MaxCircularCalls { get; set; }

Property Value

int

The maximum amount of times an object is allowed to make circular calls.

MaxDepth

Gets or sets the maximum depth to safely traverse an object hierarchy. Default is 10.

public int MaxDepth { get; set; }

Property Value

int

The maximum depth to safely traverse an object hierarchy.

ReflectionRules

Gets or sets the binding constraints for reflection based member searching.

public MemberReflection ReflectionRules { get; set; }

Property Value

MemberReflection

The binding constraints for reflection based member searching.

Exceptions

ArgumentNullException

value cannot be null.

SkipProperty

Gets or sets the function delegate that is invoked every time a public property is iterated and whose PropertyInfo determine if that property should be skipped or not.

public Func<PropertyInfo, bool> SkipProperty { get; set; }

Property Value

Func<PropertyInfo, bool>

A Func<TResult> that determines if a given PropertyInfo should be skipped or not.

SkipPropertyType

Gets or sets the function delegate that is invoked just before public properties is being iterated and whose return Type determine if the properties should be skipped or not.

public Func<Type, bool> SkipPropertyType { get; set; }

Property Value

Func<Type, bool>

A Func<TResult> that determines if a given property Type should be skipped or not.

ValueResolver

Gets or sets the function delegate that is invoked when a property can be read and is of same type as the underlying Type of the source object.

public Func<object, PropertyInfo, object> ValueResolver { get; set; }

Property Value

Func<object, PropertyInfo, object>

A function delegate that is invoked when a property can be read and is of same type as the underlying Type of the source object.

See Also