Class ResourceExtensions
Extension methods for tree navigation on IResource instances.
public static class ResourceExtensions
- Inheritance
-
ResourceExtensions
- Inherited Members
Methods
FindAll(IResource, Func<IResource, bool>)
Finds all descendants matching a predicate.
public static IEnumerable<IResource> FindAll(this IResource resource, Func<IResource, bool> predicate)
Parameters
Returns
- IEnumerable<IResource>
All matching descendants.
FindByPath(IResource, string, string)
Finds a descendant resource by relative path.
public static IResource FindByPath(this IResource resource, string path, string separator = "/")
Parameters
resourceIResourceThe starting resource.
pathstringRelative path (e.g., "DatabaseEngine_abc/ComponentTable_Player").
separatorstringPath separator (default: "/").
Returns
- IResource
The resource at the path, or null if not found.
FindFirst(IResource, Func<IResource, bool>)
Finds the first descendant matching a predicate.
public static IResource FindFirst(this IResource resource, Func<IResource, bool> predicate)
Parameters
Returns
- IResource
First matching descendant, or null if none found.
GetAncestors(IResource)
Gets all ancestors of this resource, starting from the immediate parent up to the root.
public static IEnumerable<IResource> GetAncestors(this IResource resource)
Parameters
resourceIResourceThe resource to get ancestors for.
Returns
- IEnumerable<IResource>
Ancestors from parent to root (nearest first).
GetDepth(IResource)
Gets the depth of this resource in the tree (root = 0).
public static int GetDepth(this IResource resource)
Parameters
resourceIResourceThe resource to measure.
Returns
- int
Depth from root.
GetDescendantCount(IResource)
Gets the total count of descendants.
public static int GetDescendantCount(this IResource resource)
Parameters
resourceIResourceThe resource to count from.
Returns
- int
Total number of descendants.
GetDescendants(IResource)
Gets all descendants of this resource using depth-first traversal.
public static IEnumerable<IResource> GetDescendants(this IResource resource)
Parameters
resourceIResourceThe resource to get descendants for.
Returns
- IEnumerable<IResource>
All descendants (children, grandchildren, etc.).
GetMetricSources(IResource)
Finds all metric sources in the subtree rooted at this resource.
public static IEnumerable<IMetricSource> GetMetricSources(this IResource resource)
Parameters
resourceIResourceThe starting resource.
Returns
- IEnumerable<IMetricSource>
All IMetricSource implementations in the subtree, including self if applicable.
Remarks
Uses runtime is checks during depth-first traversal to discover metric sources.
This approach is acceptable because:
- Snapshots are taken every 1-5 seconds, not on the hot path
- Tree walk is already required for path building and hierarchy
- For 100 nodes: ~1.5μs per snapshot — negligible overhead
GetPath(IResource, string)
Gets the full path from root to this resource.
public static string GetPath(this IResource resource, string separator = "/")
Parameters
resourceIResourceThe resource to get the path for.
separatorstringPath separator (default: "/").
Returns
- string
Full path string (e.g., "Root/DataEngine/DatabaseEngine_abc123").
IsAncestorOf(IResource, IResource)
Checks if this resource is an ancestor of another resource.
public static bool IsAncestorOf(this IResource resource, IResource other)
Parameters
Returns
- bool
True if this resource is an ancestor of other.
IsDescendantOf(IResource, IResource)
Checks if this resource is a descendant of another resource.
public static bool IsDescendantOf(this IResource resource, IResource other)
Parameters
Returns
- bool
True if this resource is a descendant of other.