dotnet/roslyn

Add predicate version of IOperation.Descendants

オープン

#53,621 opened on 2021/05/22

 (1 件のコメント) (0 件のリアクション) (1 人の担当者)C# (4,257 件のフォーク)batch import
Area-CompilersConcept-APIFeature - IOperationFeature Requestapi-approvedhelp wanted

Repository metrics

Stars
 (20,414 個のスター)
PR merge metrics
 (平均マージ 6d 17h) (30d で 256 merged PRs)

説明

Background and Motivation

Today, we have a SyntaxNode helper DescendantsNodes that takes a predicate descendIntoChildren, which allows users to cut off enumeration if needed. We don't have a similar method for IOperation: Descendants does not take a predicate that can control this. We should add a companion method for IOperation here.

Proposed API

namespace Microsoft.CodeAnalysis.Operations
{
    public static class OperationExtensions
    {
+       public static IEnumerable<IOperation> Descendants(this IOperation? operation, Func<IOperation, bool> descendIntoChildren);
+       public static IEnumerable<IOperation> DescendantsAndSelf(this IOperation? operation, Func<IOperation, bool> descendIntoChildren);
    }

Usage examples

Where I need this currently is to express something like operation.Descendants(descendIntoChildren: static node => node is not (IAnonymousFunctionOperation or ILocalFunctionOperation)), where I need to cut off enumeration into lambdas or local functions.

Alternatives

N/A

Risks

Ideally, we'd name it DescendantNodes for consistency with syntax, but that ship sailed long ago.

コントリビューターガイド