Background
IntermediateNodeCollection is the collection type used for Children on all IR nodes. It currently doesn't implement IReadOnlyList<IntermediateNode>, which means code that needs to check types of all children (e.g., AreAllChildrenOfType<T>) requires custom helper methods instead of using standard LINQ/pattern matching.
What to change
Make IntermediateNodeCollection implement IReadOnlyList<IntermediateNode> (it likely already has the necessary indexer and Count).
Files to update
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateNodeCollection.cs
- Verify no downstream compilation issues from the interface addition.
Notes
- This is an additive change — existing code continues to work.
- Enables patterns like
children.All(c => c is HtmlIntermediateToken) and list pattern matching.
- The collection is internal, so there are no public API concerns.
ref: PR #12957 review comment #12957 (comment)
Background
IntermediateNodeCollectionis the collection type used forChildrenon all IR nodes. It currently doesn't implementIReadOnlyList<IntermediateNode>, which means code that needs to check types of all children (e.g.,AreAllChildrenOfType<T>) requires custom helper methods instead of using standard LINQ/pattern matching.What to change
Make
IntermediateNodeCollectionimplementIReadOnlyList<IntermediateNode>(it likely already has the necessary indexer and Count).Files to update
src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Intermediate/IntermediateNodeCollection.csNotes
children.All(c => c is HtmlIntermediateToken)and list pattern matching.ref: PR #12957 review comment #12957 (comment)