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


C# DiagnosticDescriptor类代码示例

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


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


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