HierarchyOptions Class
Definition
- Namespace
- Cuemon.Extensions.Runtime
- Assemblies
- Cuemon.Extensions.Core.dll
Specifies options that is related to Hierarchy and HierarchySerializer operations.
public class HierarchyOptions : IParameterObject
- Inheritance
-
objectHierarchyOptions
- Implements
- Extension Methods
Examples
The following example demonstrates how to configure
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
| Name | Description |
|---|---|
| HierarchyOptions() | Initializes a new instance of the HierarchyOptions class. |
Properties
| Name | Description |
|---|---|
| HasCircularReference | Gets or sets the function delegate that is invoked when a property has a value and whose return value suggest a circular reference. |
| MaxCircularCalls | Gets or sets the maximum amount of times an object is allowed to make circular calls. Default is 2. |
| MaxDepth | Gets or sets the maximum depth to safely traverse an object hierarchy. Default is 10. |
| ReflectionRules | Gets or sets the binding constraints for reflection based member searching. |
| 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. |
| 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. |
| 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. |