コード例 #1
0
        private static void ComputeRefactoring(
            RefactoringContext context,
            SyntaxNode node,
            BlockSyntax body,
            SemanticModel semanticModel)
        {
            if (body?.ContainsYieldReturn() != true)
            {
                return;
            }

            if (!(semanticModel.GetDeclaredSymbol(node, context.CancellationToken) is IMethodSymbol methodSymbol))
            {
                return;
            }

            ITypeSymbol type = GetElementType(methodSymbol.ReturnType, semanticModel);

            if (type?.IsErrorType() != false)
            {
                return;
            }

            context.RegisterRefactoring(
                "Use List<T> instead of yield",
                cancellationToken => RefactorAsync(context.Document, type, body, body.Statements, cancellationToken),
                RefactoringIdentifiers.UseListInsteadOfYield);
        }