当前位置: 首页>>代码示例>>C#>>正文


C# SyntaxTreeAnalysisContext.GetStyleCopSettings方法代码示例

本文整理汇总了C#中SyntaxTreeAnalysisContext.GetStyleCopSettings方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTreeAnalysisContext.GetStyleCopSettings方法的具体用法?C# SyntaxTreeAnalysisContext.GetStyleCopSettings怎么用?C# SyntaxTreeAnalysisContext.GetStyleCopSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SyntaxTreeAnalysisContext的用法示例。


在下文中一共展示了SyntaxTreeAnalysisContext.GetStyleCopSettings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleSyntaxTreeAxtion

        private static void HandleSyntaxTreeAxtion(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    // make sure that both \n and \r\n are accepted from the settings.
                    var reformattedCopyrightText = settings.DocumentationRules.CopyrightText.Replace("\r\n", "\n").Replace("\n", Environment.NewLine);
                    if (string.CompareOrdinal(fileHeader.CopyrightText, reformattedCopyrightText) != 0)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                    }
                }
            }
        }
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:67,代码来源:FileHeaderAnalyzers.cs

示例2: HandleSyntaxTreeAction

        private static void HandleSyntaxTreeAction(SyntaxTreeAnalysisContext context, Compilation compilation)
        {
            var root = context.Tree.GetRoot(context.CancellationToken);
            var settings = context.GetStyleCopSettings();

            // don't process empty files
            if (root.FullSpan.IsEmpty)
            {
                return;
            }

            if (settings.DocumentationRules.XmlHeader)
            {
                var fileHeader = FileHeaderHelpers.ParseXmlFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (fileHeader.IsMalformed)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMalformed, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1634Identifier))
                {
                    CheckCopyrightHeader(context, compilation, settings, fileHeader);
                }

                if (!compilation.IsAnalyzerSuppressed(SA1639Identifier))
                {
                    CheckSummaryHeader(context, compilation, fileHeader);
                }
            }
            else
            {
                var fileHeader = FileHeaderHelpers.ParseFileHeader(root);
                if (fileHeader.IsMissing)
                {
                    context.ReportDiagnostic(Diagnostic.Create(SA1633DescriptorMissing, fileHeader.GetLocation(context.Tree)));
                    return;
                }

                if (!compilation.IsAnalyzerSuppressed(SA1635Identifier))
                {
                    if (string.IsNullOrWhiteSpace(fileHeader.CopyrightText))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1635Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }

                    if (compilation.IsAnalyzerSuppressed(SA1636Identifier))
                    {
                        return;
                    }

                    if (!CompareCopyrightText(fileHeader.CopyrightText, settings))
                    {
                        context.ReportDiagnostic(Diagnostic.Create(SA1636Descriptor, fileHeader.GetLocation(context.Tree)));
                        return;
                    }
                }
            }
        }
开发者ID:journeyman,项目名称:StyleCopAnalyzers,代码行数:66,代码来源:FileHeaderAnalyzers.cs


注:本文中的SyntaxTreeAnalysisContext.GetStyleCopSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。