• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DiagnosticDescriptor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DiagnosticDescriptor的典型用法代码示例。如果您正苦于以下问题:C# DiagnosticDescriptor类的具体用法?C# DiagnosticDescriptor怎么用?C# DiagnosticDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DiagnosticDescriptor类属于命名空间,在下文中一共展示了DiagnosticDescriptor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateDiagnostic

 public static Diagnostic CreateDiagnostic(
     this ISymbol symbol,
     DiagnosticDescriptor rule,
     params object[] args)
 {
     return symbol.Locations.CreateDiagnostic(rule, args);
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:DiagnosticExtensions.cs


示例2: CreateDiagnostic

 public static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, params object[] args)
 {
     return Diagnostic.Create(descriptor,
              location: null,
              additionalLocations: null,
              messageArgs: args);
 }
开发者ID:blinds52,项目名称:binskim,代码行数:7,代码来源:TestRoslynAnalyzer.cs


示例3: TestDiagnostic

 public TestDiagnostic(DiagnosticDescriptor descriptor, string kind, DiagnosticSeverity severity, Location location, string message, params object[] arguments)
 {
     _descriptor = descriptor;
     _kind = kind;
     _severity = severity;
     _location = location;
     _message = message;
     _arguments = arguments;
 }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:9,代码来源:DiagnosticAnalyzerTests.cs


示例4: GetGlobalResult

 protected static DiagnosticResult GetGlobalResult(DiagnosticDescriptor rule, params string[] messageArguments)
 {
     return new DiagnosticResult
     {
         Id = rule.Id,
         Severity = rule.DefaultSeverity,
         Message = rule.MessageFormat.ToString()
     };
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:9,代码来源:DiagnosticAnalyzerTestBase.cs


示例5: CreateDiagnostics

 public static IEnumerable<Diagnostic> CreateDiagnostics(
     this IEnumerable<ISymbol> symbols,
     DiagnosticDescriptor rule,
     params object[] args)
 {
     foreach (var symbol in symbols)
     {
         yield return symbol.CreateDiagnostic(rule, args);
     }
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:DiagnosticExtensions.cs


示例6: Diagnostic

        public Diagnostic(Location location, DiagnosticDescriptor descriptor, params object[] messageArgs) {

            if(location == null) {
                throw new ArgumentNullException(nameof(location));
            }
            if(descriptor == null) {
                throw new ArgumentNullException(nameof(descriptor));
            }

            Location     = location;
            Descriptor   = descriptor;
            _messageArgs = messageArgs?? EmptyMessageArgs;
        }
开发者ID:IInspectable,项目名称:Nav.Language.Extensions,代码行数:13,代码来源:Diagnostic.cs


示例7: GetClassificationIdDescriptor

        private DiagnosticDescriptor GetClassificationIdDescriptor()
        {
            if (_classificationIdDescriptor == null)
            {
                var titleAndMessageFormat = GetTitleAndMessageFormatForClassificationIdDescriptor();
                _classificationIdDescriptor =
                    new DiagnosticDescriptor(IDEDiagnosticIds.RemoveUnnecessaryImportsDiagnosticId,
                                             titleAndMessageFormat,
                                             titleAndMessageFormat,
                                             DiagnosticCategory.Style,
                                             DiagnosticSeverity.Hidden,
                                             isEnabledByDefault: true,
                                             customTags: DiagnosticCustomTags.Unnecessary);
            }

            return _classificationIdDescriptor;
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:17,代码来源:RemoveUnnecessaryImportsDiagnosticAnalyzerBase.cs


示例8: CSharpTypeStyleDiagnosticAnalyzerBase

 public CSharpTypeStyleDiagnosticAnalyzerBase(string diagnosticId, LocalizableString title, LocalizableString message)
 {
     _diagnosticId = diagnosticId;
     _title = title;
     _message = message;
     _noneDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Hidden);
     _infoDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Info);
     _warningDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Warning);
     _errorDiagnosticDescriptor = CreateDiagnosticDescriptor(DiagnosticSeverity.Error);
     _severityToDescriptorMap =
         new Dictionary<DiagnosticSeverity, DiagnosticDescriptor>
         {
             {DiagnosticSeverity.Hidden, _noneDiagnosticDescriptor },
             {DiagnosticSeverity.Info, _infoDiagnosticDescriptor },
             {DiagnosticSeverity.Warning, _warningDiagnosticDescriptor },
             {DiagnosticSeverity.Error, _errorDiagnosticDescriptor },
         };
 }
开发者ID:xyh413,项目名称:roslyn,代码行数:18,代码来源:CSharpTypeStyleDiagnosticAnalyzerBase.cs


示例9: SymbolAction

        private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences)
        {
            if (preferences.TryGetApplicableRule(context.Symbol, out var applicableRule))
            {
                if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
                    !applicableRule.IsNameCompliant(context.Symbol.Name, out var failureReason))
                {
                    var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
                         s_localizableTitleNamingStyle,
                         string.Format(FeaturesResources.Naming_rule_violation_0, failureReason),
                         DiagnosticCategory.Style,
                         applicableRule.EnforcementLevel,
                         isEnabledByDefault: true);

                    var builder = ImmutableDictionary.CreateBuilder<string, string>();
                    builder[nameof(NamingStyle)] = applicableRule.NamingStyle.CreateXElement().ToString();
                    builder["OptionName"] = nameof(SimplificationOptions.NamingPreferences);
                    builder["OptionLanguage"] = context.Compilation.Language;
                    context.ReportDiagnostic(Diagnostic.Create(descriptor, context.Symbol.Locations.First(), builder.ToImmutable()));
                }
            }
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:22,代码来源:NamingStyleDiagnosticAnalyzerBase.cs


示例10: TestGetEffectiveDiagnostics

        private void TestGetEffectiveDiagnostics()
        {
            var noneDiagDescriptor = new DiagnosticDescriptor("XX0001", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Hidden, isEnabledByDefault: true);
            var infoDiagDescriptor = new DiagnosticDescriptor("XX0002", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Info, isEnabledByDefault: true);
            var warningDiagDescriptor = new DiagnosticDescriptor("XX0003", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: true);
            var errorDiagDescriptor = new DiagnosticDescriptor("XX0004", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Error, isEnabledByDefault: true);

            var noneDiag = CodeAnalysis.Diagnostic.Create(noneDiagDescriptor, Location.None);
            var infoDiag = CodeAnalysis.Diagnostic.Create(infoDiagDescriptor, Location.None);
            var warningDiag = CodeAnalysis.Diagnostic.Create(warningDiagDescriptor, Location.None);
            var errorDiag = CodeAnalysis.Diagnostic.Create(errorDiagDescriptor, Location.None);

            var diags = new[] { noneDiag, infoDiag, warningDiag, errorDiag };

            // Escalate all diagnostics to error.
            var specificDiagOptions = new Dictionary<string, ReportDiagnostic>();
            specificDiagOptions.Add(noneDiagDescriptor.Id, ReportDiagnostic.Error);
            specificDiagOptions.Add(infoDiagDescriptor.Id, ReportDiagnostic.Error);
            specificDiagOptions.Add(warningDiagDescriptor.Id, ReportDiagnostic.Error);
            var options = TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(specificDiagOptions);

            var comp = CreateCompilationWithMscorlib45("", options: options);
            var effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(diags.Length, effectiveDiags.Length);
            foreach (var effectiveDiag in effectiveDiags)
            {
                Assert.True(effectiveDiag.Severity == DiagnosticSeverity.Error);
            }

            // Suppress all diagnostics.
            specificDiagOptions = new Dictionary<string, ReportDiagnostic>();
            specificDiagOptions.Add(noneDiagDescriptor.Id, ReportDiagnostic.Suppress);
            specificDiagOptions.Add(infoDiagDescriptor.Id, ReportDiagnostic.Suppress);
            specificDiagOptions.Add(warningDiagDescriptor.Id, ReportDiagnostic.Suppress);
            specificDiagOptions.Add(errorDiagDescriptor.Id, ReportDiagnostic.Suppress);
            options = TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(specificDiagOptions);

            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(0, effectiveDiags.Length);

            // Shuffle diagnostic severity.
            specificDiagOptions = new Dictionary<string, ReportDiagnostic>();
            specificDiagOptions.Add(noneDiagDescriptor.Id, ReportDiagnostic.Info);
            specificDiagOptions.Add(infoDiagDescriptor.Id, ReportDiagnostic.Hidden);
            specificDiagOptions.Add(warningDiagDescriptor.Id, ReportDiagnostic.Error);
            specificDiagOptions.Add(errorDiagDescriptor.Id, ReportDiagnostic.Warn);
            options = TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(specificDiagOptions);

            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(diags.Length, effectiveDiags.Length);
            var diagIds = new HashSet<string>(diags.Select(d => d.Id));
            foreach (var effectiveDiag in effectiveDiags)
            {
                Assert.True(diagIds.Remove(effectiveDiag.Id));

                switch (effectiveDiag.Severity)
                {
                    case DiagnosticSeverity.Hidden:
                        Assert.Equal(infoDiagDescriptor.Id, effectiveDiag.Id);
                        break;

                    case DiagnosticSeverity.Info:
                        Assert.Equal(noneDiagDescriptor.Id, effectiveDiag.Id);
                        break;

                    case DiagnosticSeverity.Warning:
                        Assert.Equal(errorDiagDescriptor.Id, effectiveDiag.Id);
                        break;

                    case DiagnosticSeverity.Error:
                        Assert.Equal(warningDiagDescriptor.Id, effectiveDiag.Id);
                        break;

                    default:
                        throw ExceptionUtilities.Unreachable;
                }
            }

            Assert.Empty(diagIds);
        }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:82,代码来源:DiagnosticAnalyzerTests.cs


示例11: TestEffectiveSeverity

 private static void TestEffectiveSeverity(
     DiagnosticSeverity defaultSeverity,
     ReportDiagnostic expectedEffectiveSeverity,
     Dictionary<string, ReportDiagnostic> specificOptions = null,
     ReportDiagnostic generalOption = ReportDiagnostic.Default,
     bool isEnabledByDefault = true)
 {
     specificOptions = specificOptions ?? new Dictionary<string, ReportDiagnostic>();
     var options = new CSharpCompilationOptions(OutputKind.ConsoleApplication, generalDiagnosticOption: generalOption, specificDiagnosticOptions: specificOptions);
     var descriptor = new DiagnosticDescriptor(id: "Test0001", title: "Test0001", messageFormat: "Test0001", category: "Test0001", defaultSeverity: defaultSeverity, isEnabledByDefault: isEnabledByDefault);
     var effectiveSeverity = descriptor.GetEffectiveSeverity(options);
     Assert.Equal(expectedEffectiveSeverity, effectiveSeverity);
 }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:13,代码来源:DiagnosticAnalyzerTests.cs


示例12: GetResultAt

        protected static DiagnosticResult GetResultAt(string path, int line, int column, DiagnosticDescriptor rule, params object[] messageArguments)
        {
            var location = new DiagnosticResultLocation(path, line, column);

            return new DiagnosticResult
            {
                Locations = new[] { location },
                Id = rule.Id,
                Severity = rule.DefaultSeverity,
                Message = string.Format(rule.MessageFormat.ToString(), messageArguments)
            };
        }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:12,代码来源:DiagnosticAnalyzerTestBase.cs


示例13: GetCSharpResultAt

 protected static DiagnosticResult GetCSharpResultAt(int line, int column, DiagnosticDescriptor rule, params object[] messageArguments)
 {
     return GetResultAt(CSharpDefaultFilePath, line, column, rule, messageArguments);
 }
开发者ID:Anniepoh,项目名称:roslyn-analyzers,代码行数:4,代码来源:DiagnosticAnalyzerTestBase.cs


示例14: GetEffectiveSeverity

 private static ReportDiagnostic GetEffectiveSeverity(DiagnosticDescriptor descriptor, CompilationOptions options)
 {
     return options == null
         ? MapSeverityToReport(descriptor.DefaultSeverity)
         : descriptor.GetEffectiveSeverity(options);
 }
开发者ID:nevinclement,项目名称:roslyn,代码行数:6,代码来源:DiagnosticIncrementalAnalyzer.cs


示例15: CreateAnalyzerExceptionDiagnostic

        /// <summary>
        /// Create a diagnostic for exception thrown by the given analyzer.
        /// </summary>
        /// <remarks>
        /// Keep this method in sync with "AnalyzerExecutor.CreateAnalyzerExceptionDiagnostic".
        /// </remarks>
        internal static Diagnostic CreateAnalyzerExceptionDiagnostic(DiagnosticAnalyzer analyzer, Exception e)
        {
            var analyzerName = analyzer.ToString();

            // TODO: It is not ideal to create a new descriptor per analyzer exception diagnostic instance.
            // However, until we add a LongMessage field to the Diagnostic, we are forced to park the instance specific description onto the Descriptor's Description field.
            // This requires us to create a new DiagnosticDescriptor instance per diagnostic instance.
            var descriptor = new DiagnosticDescriptor(AnalyzerExceptionDiagnosticId,
                title: FeaturesResources.User_Diagnostic_Analyzer_Failure,
                messageFormat: FeaturesResources.Analyzer_0_threw_an_exception_of_type_1_with_message_2,
                description: string.Format(FeaturesResources.Analyzer_0_threw_the_following_exception_colon_1, analyzerName, e.CreateDiagnosticDescription()),
                category: AnalyzerExceptionDiagnosticCategory,
                defaultSeverity: DiagnosticSeverity.Warning,
                isEnabledByDefault: true,
                customTags: WellKnownDiagnosticTags.AnalyzerException);

            return Diagnostic.Create(descriptor, Location.None, analyzerName, e.GetType(), e.Message);
        }
开发者ID:natidea,项目名称:roslyn,代码行数:24,代码来源:AnalyzerHelper.cs


示例16: ChangeSeverity

 public void ChangeSeverity()
 {
     _rule = new DiagnosticDescriptor("test", "test", "test", "test", DiagnosticSeverity.Warning, true);
 }
开发者ID:nbsoftwarecsjava,项目名称:roslyn,代码行数:4,代码来源:DiagnosticsSquiggleTaggerProviderTests.cs


示例17: GetDiagnostic

            internal async Task<IEnumerable<Diagnostic>> GetDiagnostic(SyntaxTree tree, DiagnosticDescriptor diagnosticDescriptor, CancellationToken cancellationToken)
            {
                try
                {
                    // This can be called on a background thread. We are being asked whether a 
                    // lightbulb should be shown for the given document, but we only know about the 
                    // current state of the buffer. Compare the text to see if we should bail early.
                    // Even if the text is the same, the buffer may change on the UI thread during this
                    // method. If it does, we may give an incorrect response, but the diagnostics 
                    // engine will know that the document changed and not display the lightbulb anyway.

                    if (Buffer.AsTextContainer().CurrentText != await tree.GetTextAsync(cancellationToken).ConfigureAwait(false))
                    {
                        return SpecializedCollections.EmptyEnumerable<Diagnostic>();
                    }

                    TrackingSession trackingSession;
                    if (CanInvokeRename(out trackingSession, waitForResult: true, cancellationToken: cancellationToken))
                    {
                        SnapshotSpan snapshotSpan = trackingSession.TrackingSpan.GetSpan(Buffer.CurrentSnapshot);
                        var textSpan = snapshotSpan.Span.ToTextSpan();

                        var builder = ImmutableDictionary.CreateBuilder<string, string>();
                        builder.Add(RenameTrackingDiagnosticAnalyzer.RenameFromPropertyKey, trackingSession.OriginalName);
                        builder.Add(RenameTrackingDiagnosticAnalyzer.RenameToPropertyKey, snapshotSpan.GetText());
                        var properties = builder.ToImmutable();

                        var diagnostic = Diagnostic.Create(diagnosticDescriptor,
                            tree.GetLocation(textSpan),
                            properties);

                        return SpecializedCollections.SingletonEnumerable(diagnostic);
                    }

                    return SpecializedCollections.EmptyEnumerable<Diagnostic>();
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:41,代码来源:RenameTrackingTaggerProvider.StateMachine.cs


示例18: TestGetEffectiveDiagnosticsGlobal

        public void TestGetEffectiveDiagnosticsGlobal()
        {
            var noneDiagDescriptor = new DiagnosticDescriptor("XX0001", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Hidden, isEnabledByDefault: true);
            var infoDiagDescriptor = new DiagnosticDescriptor("XX0002", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Info, isEnabledByDefault: true);
            var warningDiagDescriptor = new DiagnosticDescriptor("XX0003", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: true);
            var errorDiagDescriptor = new DiagnosticDescriptor("XX0004", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Error, isEnabledByDefault: true);

            var noneDiag = Microsoft.CodeAnalysis.Diagnostic.Create(noneDiagDescriptor, Location.None);
            var infoDiag = Microsoft.CodeAnalysis.Diagnostic.Create(infoDiagDescriptor, Location.None);
            var warningDiag = Microsoft.CodeAnalysis.Diagnostic.Create(warningDiagDescriptor, Location.None);
            var errorDiag = Microsoft.CodeAnalysis.Diagnostic.Create(errorDiagDescriptor, Location.None);

            var diags = new[] { noneDiag, infoDiag, warningDiag, errorDiag };

            var options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Default);
            var comp = CreateCompilationWithMscorlib45("", options: options);
            var effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(4, effectiveDiags.Length);

            options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Error);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(4, effectiveDiags.Length);
            Assert.Equal(1, effectiveDiags.Count(d => d.IsWarningAsError));

            options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Warn);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(4, effectiveDiags.Length);
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Error));
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Warning));

            options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Info);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(4, effectiveDiags.Length);
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Error));
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Info));

            options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Hidden);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(4, effectiveDiags.Length);
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Error));
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Hidden));

            options = TestOptions.ReleaseDll.WithGeneralDiagnosticOption(ReportDiagnostic.Suppress);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(2, effectiveDiags.Length);
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Error));
            Assert.Equal(1, effectiveDiags.Count(d => d.Severity == DiagnosticSeverity.Hidden));
        }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:53,代码来源:DiagnosticAnalyzerTests.cs


示例19: TryCreate

        public static bool TryCreate(DiagnosticDescriptor descriptor, string[] messageArguments, ProjectId projectId, Workspace workspace, out DiagnosticData diagnosticData, CancellationToken cancellationToken = default(CancellationToken))
        {
            diagnosticData = null;
            var project = workspace.CurrentSolution.GetProject(projectId);
            if (project == null)
            {
                return false;
            }

            var diagnostic = Diagnostic.Create(descriptor, Location.None, messageArguments);
            if (project.SupportsCompilation)
            {
                // Get diagnostic with effective severity.
                // Additionally, if the diagnostic was suppressed by a source suppression, effectiveDiagnostics will have a diagnostic with IsSuppressed = true.
                var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken);
                var effectiveDiagnostics = CompilationWithAnalyzers.GetEffectiveDiagnostics(SpecializedCollections.SingletonEnumerable(diagnostic), compilation);
                if (effectiveDiagnostics == null || effectiveDiagnostics.IsEmpty())
                {
                    // Rule is disabled by compilation options.
                    return false;
                }

                diagnostic = effectiveDiagnostics.Single();
            }

            diagnosticData = diagnostic.ToDiagnosticData(project);
            return true;
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:28,代码来源:DiagnosticData.cs


示例20: TestDisabledDiagnostics

        private void TestDisabledDiagnostics()
        {
            var disabledDiagDescriptor = new DiagnosticDescriptor("XX001", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: false);
            var enabledDiagDescriptor = new DiagnosticDescriptor("XX002", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: true);

            var disabledDiag = CodeAnalysis.Diagnostic.Create(disabledDiagDescriptor, Location.None);
            var enabledDiag = CodeAnalysis.Diagnostic.Create(enabledDiagDescriptor, Location.None);

            var diags = new[] { disabledDiag, enabledDiag };

            // Verify that only the enabled diag shows up after filtering.
            var options = TestOptions.ReleaseDll;
            var comp = CreateCompilationWithMscorlib45("", options: options);
            var effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(1, effectiveDiags.Length);
            Assert.Contains(enabledDiag, effectiveDiags);

            // If the disabled diag was enabled through options, then it should show up.
            var specificDiagOptions = new Dictionary<string, ReportDiagnostic>();
            specificDiagOptions.Add(disabledDiagDescriptor.Id, ReportDiagnostic.Warn);
            specificDiagOptions.Add(enabledDiagDescriptor.Id, ReportDiagnostic.Suppress);

            options = TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(specificDiagOptions);
            comp = CreateCompilationWithMscorlib45("", options: options);
            effectiveDiags = comp.GetEffectiveDiagnostics(diags).ToArray();
            Assert.Equal(1, effectiveDiags.Length);
            Assert.Contains(disabledDiag, effectiveDiags);
        }
开发者ID:anshita-arya,项目名称:roslyn,代码行数:28,代码来源:DiagnosticAnalyzerTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DiagnosticInfo类代码示例发布时间:2022-05-24
下一篇:
C# DiagnosticBag类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap