Ejemplo n.º 1
0
        private static AddExceptionToDocumentationCommentAnalysisResult Analyze(
            SyntaxNode node,
            ExpressionSyntax expression,
            INamedTypeSymbol exceptionSymbol,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            if (!(semanticModel.GetTypeSymbol(expression, cancellationToken) is INamedTypeSymbol typeSymbol))
            {
                return(Fail);
            }

            if (!InheritsFromException(typeSymbol, exceptionSymbol))
            {
                return(Fail);
            }

            ISymbol declarationSymbol = GetDeclarationSymbol(node.SpanStart, semanticModel, cancellationToken);

            if (!(declarationSymbol?.GetSyntax(cancellationToken) is MemberDeclarationSyntax containingMember))
            {
                return(Fail);
            }

            DocumentationCommentTriviaSyntax comment = containingMember.GetSingleLineDocumentationComment();

            if (comment == null)
            {
                return(Fail);
            }

            if (!CanAddExceptionToComment(comment, typeSymbol, semanticModel, cancellationToken))
            {
                return(Fail);
            }

            ThrowInfo throwInfo = ThrowInfo.Create(node, typeSymbol, declarationSymbol);

            return(new AddExceptionToDocumentationCommentAnalysisResult(throwInfo, comment.ParentTrivia));
        }
 public IParameterSymbol GetParameterSymbol(SemanticModel semanticModel, CancellationToken cancellationToken)
 {
     return(ThrowInfo?.GetParameterSymbol(semanticModel, cancellationToken));
 }
 internal AddExceptionToDocumentationCommentAnalysisResult(ThrowInfo info, SyntaxTrivia documentationComment)
 {
     ThrowInfo            = info;
     DocumentationComment = documentationComment;
 }