diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs index a3af4b46e..911423dc5 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/AstNode.cs @@ -308,6 +308,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return null; } + /// + /// Gets the first child occupying , or null if the slot is empty (or the + /// node declares no such slot). The result type is inferred from the typed slot. + /// + public T? GetChild(CSharpSlotInfo slot) where T : AstNode => GetChildByRole(slot.Kind); + public T? GetParent() where T : AstNode { return Ancestors.OfType().FirstOrDefault(); @@ -327,11 +333,17 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax return collection != null ? (AstNodeCollection)collection : new AstNodeCollection(this, kind); } + /// Gets the collection occupying ; the element type is inferred from the slot. + public AstNodeCollection GetChildren(CSharpSlotInfo slot) where T : AstNode => GetChildrenByRole(slot.Kind); + protected void SetChildByRole(SlotKind kind, T? newChild) where T : AstNode { SetChildByRoleUntyped(kind, newChild); } + /// Sets the single child occupying ; the child type is inferred from the slot. + protected void SetChild(CSharpSlotInfo slot, T? newChild) where T : AstNode => SetChildByRole(slot.Kind, newChild); + #region Slot storage contract // Each concrete node's slots form a flattened child-index space, in source-declaration order. // A single slot occupies exactly one index (even when empty, where GetChild returns null); a