diff --git a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs index 874a4777b717f754efd96cdf561f719985e592e9..37bc00aa5b8c8976cea8e0f33d867aee20119ce2 100644 --- a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs +++ b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs @@ -182,7 +182,7 @@ public abstract partial class Diagnostic : IEquatable, IFormattable var warningLevel = GetDefaultWarningLevel(effectiveSeverity, descriptor.DefaultSeverity); return SimpleDiagnostic.Create( descriptor, - severity: effectiveSeverity.ToDiagnosticSeverity(descriptor.DefaultSeverity), + severity: effectiveSeverity.ToDiagnosticSeverity() ?? descriptor.DefaultSeverity, warningLevel: warningLevel, location: location ?? Location.None, additionalLocations: additionalLocations, diff --git a/src/Compilers/Core/Portable/Diagnostic/ReportDiagnosticExtensions.cs b/src/Compilers/Core/Portable/Diagnostic/ReportDiagnosticExtensions.cs index c5da2e778b476ac5215b4625e3388cdc65e9bbcb..32b56e979f6096a70a579d4c63795f1001884c85 100644 --- a/src/Compilers/Core/Portable/Diagnostic/ReportDiagnosticExtensions.cs +++ b/src/Compilers/Core/Portable/Diagnostic/ReportDiagnosticExtensions.cs @@ -6,7 +6,7 @@ namespace Microsoft.CodeAnalysis { public static class ReportDiagnosticExtensions { - public static DiagnosticSeverity ToDiagnosticSeverity(this ReportDiagnostic reportDiagnostic, DiagnosticSeverity defaultSeverity) + public static DiagnosticSeverity? ToDiagnosticSeverity(this ReportDiagnostic reportDiagnostic) { switch (reportDiagnostic) { @@ -24,7 +24,7 @@ public static DiagnosticSeverity ToDiagnosticSeverity(this ReportDiagnostic repo case ReportDiagnostic.Suppress: case ReportDiagnostic.Default: - return defaultSeverity; + return null; default: throw ExceptionUtilities.UnexpectedValue(reportDiagnostic); diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 72403fe09db9f90216a40ee6b14f76813286bb13..f83a9fc17fbd5324d884ff6ea0024bfac1a068a5 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -7,5 +7,5 @@ Microsoft.CodeAnalysis.ReportDiagnosticExtensions abstract Microsoft.CodeAnalysis.Compilation.ClassifyCommonConversion(Microsoft.CodeAnalysis.ITypeSymbol source, Microsoft.CodeAnalysis.ITypeSymbol destination) -> Microsoft.CodeAnalysis.Operations.CommonConversion static Microsoft.CodeAnalysis.Diagnostic.Create(Microsoft.CodeAnalysis.DiagnosticDescriptor descriptor, Microsoft.CodeAnalysis.Location location, Microsoft.CodeAnalysis.ReportDiagnostic effectiveSeverity, System.Collections.Generic.IEnumerable additionalLocations, System.Collections.Immutable.ImmutableDictionary properties, params object[] messageArgs) -> Microsoft.CodeAnalysis.Diagnostic static Microsoft.CodeAnalysis.DiagnosticSeverityExtensions.ToReportDiagnostic(this Microsoft.CodeAnalysis.DiagnosticSeverity diagnosticSeverity) -> Microsoft.CodeAnalysis.ReportDiagnostic -static Microsoft.CodeAnalysis.ReportDiagnosticExtensions.ToDiagnosticSeverity(this Microsoft.CodeAnalysis.ReportDiagnostic reportDiagnostic, Microsoft.CodeAnalysis.DiagnosticSeverity defaultSeverity) -> Microsoft.CodeAnalysis.DiagnosticSeverity +static Microsoft.CodeAnalysis.ReportDiagnosticExtensions.ToDiagnosticSeverity(this Microsoft.CodeAnalysis.ReportDiagnostic reportDiagnostic) -> Microsoft.CodeAnalysis.DiagnosticSeverity? static Microsoft.CodeAnalysis.ReportDiagnosticExtensions.WithDefaultSeverity(this Microsoft.CodeAnalysis.ReportDiagnostic reportDiagnostic, Microsoft.CodeAnalysis.DiagnosticSeverity defaultSeverity) -> Microsoft.CodeAnalysis.ReportDiagnostic diff --git a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOption.cs b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOption.cs index 6fe565e4696c5de2fe53d26185e334f2955bcabc..5ceeae8559b43d956e6fba095d72422c45606803 100644 --- a/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOption.cs +++ b/src/Workspaces/Core/Portable/CodeStyle/CodeStyleOption.cs @@ -49,7 +49,7 @@ public CodeStyleOption(T value, NotificationOption notification) new XAttribute(nameof(SerializationVersion), SerializationVersion), new XAttribute("Type", GetTypeNameForSerialization()), new XAttribute(nameof(Value), GetValueForSerialization()), - new XAttribute(nameof(DiagnosticSeverity), Notification.Severity.ToDiagnosticSeverity(DiagnosticSeverity.Hidden))); + new XAttribute(nameof(DiagnosticSeverity), Notification.Severity.ToDiagnosticSeverity() ?? DiagnosticSeverity.Hidden)); private object GetValueForSerialization() { diff --git a/src/Workspaces/Core/Portable/CodeStyle/NotificationOption.cs b/src/Workspaces/Core/Portable/CodeStyle/NotificationOption.cs index 93cb8e3615bcc1de9932c8a239461d2e70b1ed5e..fa2753192044ee76f9344b3e06d33b6f0f2ce017 100644 --- a/src/Workspaces/Core/Portable/CodeStyle/NotificationOption.cs +++ b/src/Workspaces/Core/Portable/CodeStyle/NotificationOption.cs @@ -25,7 +25,7 @@ public ReportDiagnostic Severity [Obsolete("Use " + nameof(Severity) + " instead.")] public DiagnosticSeverity Value { - get => Severity.ToDiagnosticSeverity(DiagnosticSeverity.Hidden); + get => Severity.ToDiagnosticSeverity() ?? DiagnosticSeverity.Hidden; set => Severity = value.ToReportDiagnostic(); } diff --git a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SerializableNamingRule.cs b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SerializableNamingRule.cs index e71ab30491054e91d577fa1920a34ccfc68db65b..01896985dc7e7e5a254b032d1d3e4a34aef4e670 100644 --- a/src/Workspaces/Core/Portable/NamingStyles/Serialization/SerializableNamingRule.cs +++ b/src/Workspaces/Core/Portable/NamingStyles/Serialization/SerializableNamingRule.cs @@ -24,7 +24,7 @@ internal XElement CreateXElement() var element = new XElement(nameof(SerializableNamingRule), new XAttribute(nameof(SymbolSpecificationID), SymbolSpecificationID), new XAttribute(nameof(NamingStyleID), NamingStyleID), - new XAttribute(nameof(EnforcementLevel), EnforcementLevel.ToDiagnosticSeverity(DiagnosticSeverity.Hidden))); + new XAttribute(nameof(EnforcementLevel), EnforcementLevel.ToDiagnosticSeverity() ?? DiagnosticSeverity.Hidden)); return element; }