RecursiveSelectControl Enum
Definition
Represents composable control flags for how an element is processed during recursive selection.
[Flags]
public enum RecursiveSelectControl
- Attributes
- Extension Methods
Fields
None = 0No flags set: the current element is neither yielded nor recursed into.
Yield = 1Primitive flag that includes the current element in the output sequence.
Recurse = 2Primitive flag that requests recursion into the current element's children.
Skip = 4Primitive flag that skips yielding the current element. Overrides Yield when both are set.
Break = 8Primitive flag that stops iteration of the remaining siblings at the current recursion level.
Exit = 16Primitive flag that terminates the entire recursive traversal immediately.
YieldOnly = 1Yield the current element only, without recursing into children.
RecurseOnly = 2Recurse into children without yielding the current element.
YieldAndRecurse = Yield | RecurseYield the current element and recurse into its children. This is the default behavior.
SkipOnly = 4Skip yielding the current element and do not recurse.
SkipAndRecurse = Recurse | SkipSkip yielding the current element, but still recurse into its children.
YieldAndBreak = Yield | BreakYield the current element, then stop traversal at the current level (like a break).
SkipAndBreak = Skip | BreakSkip yielding the current element and stop traversal at the current level.
YieldAndExit = Yield | ExitYield the current element, then stop traversal completely across all levels.
SkipAndExit = Skip | ExitSkip yielding the current element and stop traversal completely across all levels.
Examples
// Common input structure
var root = new[]
{
new Node { Name = "A", Children = { new Node { Name = "B" }, new Node { Name = "C" } } },
new Node { Name = "D" }
};
//
// RecursiveSelect using different control values
// YieldAndRecurse
var all = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.YieldAndRecurse);
// Output: A, B, C, D
// SkipOnly
var skip = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.SkipOnly);
// Output: (empty)
// YieldOnly
var yieldOnly = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.YieldOnly);
// Output: A, D
// RecurseOnly
var recurseOnly = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.RecurseOnly);
// Output: B, C
// SkipAndRecurse
var skipAndRecurse = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.SkipAndRecurse);
// Output: B, C
// YieldAndBreak
var yieldAndBreak = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.YieldAndBreak);
// Output: A
// SkipAndBreak
var skipAndBreak = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.SkipAndBreak);
// Output: (empty)
// YieldAndExit
var yieldAndExit = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.YieldAndExit);
// Output: A
// SkipAndExit
var skipAndExit = root.RecursiveSelect(
n => n.Children,
(n, i, d) => n.Name,
n => RecursiveSelectControl.SkipAndExit);
// Output: (empty)
Remarks
This enum defines composable control flags that determine whether an element should be yielded, whether its children should be traversed, and whether traversal should stop after the current element. It is a genuine FlagsAttribute bitmask: the primitive flags Yield, Recurse, Skip, Break, and Exit may be combined with the bitwise-OR operator, and the named combinations below are provided for the common cases.
Break and Recurse are orthogonal and compose: Break stops iteration of the remaining siblings at the current level, whereas Recurse requests descent into the current element's children. When both are set, the current element's children are visited first and only then are the remaining siblings skipped.
Typical usage includes returning one of these values from a Func<T, RecursiveSelectControl> to control
behavior dynamically within a recursive traversal method.
Behavior Matrix
| Combination | Yield | Recurse | Break Level | Exit All |
|---|---|---|---|---|
| SkipOnly | No | No | No | No |
| YieldOnly | Yes | No | No | No |
| YieldAndRecurse | Yes | Yes | No | No |
| YieldAndBreak | Yes | No | Yes | No |
| YieldAndExit | Yes | No | No | Yes |
| RecurseOnly | No | Yes | No | No |
| SkipAndRecurse | No | Yes | No | No |
| SkipAndBreak | No | No | Yes | No |
| SkipAndExit | No | No | No | Yes |
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |