public static void Analyze(
            SyntaxNodeAnalysisContext context,
            MemberDeclarationSyntax memberDeclaration,
            SeparatedSyntaxList <TypeParameterSyntax> typeParameters)
        {
            if (typeParameters.Any())
            {
                DocumentationCommentTriviaSyntax comment = memberDeclaration.GetSingleLineDocumentationComment();

                if (comment != null)
                {
                    ImmutableArray <string> values = DocumentationCommentAnalysis.GetAttributeValues(comment, "typeparam", "TYPEPARAM", "name");

                    if (!values.IsDefault)
                    {
                        foreach (TypeParameterSyntax typeParameter in typeParameters)
                        {
                            if (!typeParameter.IsMissing &&
                                !values.Contains(typeParameter.Identifier.ValueText))
                            {
                                context.ReportDiagnostic(
                                    DiagnosticDescriptors.AddTypeParameterToDocumentationComment,
                                    typeParameter.Identifier);
                            }
                        }
                    }
                }
            }
        }
        public static void Analyze(
            SyntaxNodeAnalysisContext context,
            MemberDeclarationSyntax memberDeclaration,
            SeparatedSyntaxList <ParameterSyntax> parameters)
        {
            if (!parameters.Any())
            {
                return;
            }

            DocumentationCommentTriviaSyntax comment = memberDeclaration.GetSingleLineDocumentationComment();

            if (comment == null)
            {
                return;
            }

            ImmutableArray <string> values = DocumentationCommentAnalysis.GetAttributeValues(comment, XmlElementKind.Param, "name");

            if (values.IsDefault)
            {
                return;
            }

            foreach (ParameterSyntax parameter in parameters)
            {
                if (!parameter.IsMissing &&
                    !values.Contains(parameter.Identifier.ValueText))
                {
                    context.ReportDiagnostic(DiagnosticDescriptors.AddParameterToDocumentationComment, parameter.Identifier);
                }
            }
        }
예제 #3
0
        public Dictionary <string, XmlElementSyntax> CreateNameElementMap(DocumentationCommentTriviaSyntax comment)
        {
            var dic = new Dictionary <string, XmlElementSyntax>();

            foreach (XmlElementSyntax element in comment.Elements(ElementName, ElementNameUppercase))
            {
                string name = DocumentationCommentAnalysis.GetAttributeValue(element, "name");

                if (!dic.ContainsKey(name))
                {
                    dic.Add(name, element);
                }
            }

            return(dic);
        }
        private static void AnalyzeSingleLineDocumentationCommentTrivia(SyntaxNodeAnalysisContext context)
        {
            var documentationComment = (DocumentationCommentTriviaSyntax)context.Node;

            SyntaxNode node = documentationComment.ParentTrivia.Token.Parent;

            (MemberDeclarationSyntax declaration, TypeParameterListSyntax typeParameterList)result = GetTypeParameterList(node);

            if (result.declaration == null)
            {
                result = GetTypeParameterList(node.Parent);

                if (result.declaration == null)
                {
                    return;
                }
            }

            SeparatedSyntaxList <TypeParameterSyntax> typeParameters = result.typeParameterList?.Parameters ?? default;

            if (!typeParameters.Any())
            {
                return;
            }

            ImmutableArray <string> values = DocumentationCommentAnalysis.GetAttributeValues(documentationComment, XmlElementKind.TypeParam, "name");

            if (values.IsDefault)
            {
                return;
            }

            foreach (TypeParameterSyntax typeParameter in typeParameters)
            {
                if (!typeParameter.IsMissing &&
                    !values.Contains(typeParameter.Identifier.ValueText))
                {
                    context.ReportDiagnostic(DiagnosticDescriptors.AddTypeParamElementToDocumentationComment, documentationComment);
                    return;
                }
            }
        }