/// <summary> /// Creates a <see cref="Diagnostic"/> instance. /// </summary> /// <param name="descriptor">A <see cref="DiagnosticDescriptor"/> describing the diagnostic.</param> /// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param> /// <param name="effectiveSeverity">Effective severity of the diagnostic.</param> /// <param name="additionalLocations"> /// An optional set of additional locations related to the diagnostic. /// Typically, these are locations of other items referenced in the message. /// If null, <see cref="Diagnostic.AdditionalLocations"/> will return an empty list. /// </param> /// <param name="properties"> /// An optional set of name-value pairs by means of which the analyzer that creates the diagnostic /// can convey more detailed information to the fixer. If null, <see cref="Diagnostic.Properties"/> will return /// <see cref="ImmutableDictionary{TKey, TValue}.Empty"/>. /// </param> /// <param name="messageArgs">Arguments to the message of the diagnostic.</param> /// <returns>The <see cref="Diagnostic"/> instance.</returns> public static Diagnostic Create( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, IEnumerable <Location> additionalLocations, ImmutableDictionary <string, string> properties, params object[] messageArgs) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } LocalizableString message; if (messageArgs == null || messageArgs.Length == 0) { message = descriptor.MessageFormat; } else { message = new LocalizableStringWithArguments(descriptor.MessageFormat, messageArgs); } return(CreateWithMessage(descriptor, location, effectiveSeverity, additionalLocations, properties, message)); }
/// <summary> /// Creates a <see cref="Diagnostic"/> instance. /// </summary> /// <param name="descriptor">A <see cref="DiagnosticDescriptor"/> describing the diagnostic.</param> /// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param> /// <param name="effectiveSeverity">Effective severity of the diagnostic.</param> /// <param name="additionalLocations"> /// An optional set of additional locations related to the diagnostic. /// Typically, these are locations of other items referenced in the message. /// If null, <see cref="Diagnostic.AdditionalLocations"/> will return an empty list. /// </param> /// <param name="properties"> /// An optional set of name-value pairs by means of which the analyzer that creates the diagnostic /// can convey more detailed information to the fixer. If null, <see cref="Diagnostic.Properties"/> will return /// <see cref="ImmutableDictionary{TKey, TValue}.Empty"/>. /// </param> /// <param name="messageArgs">Arguments to the message of the diagnostic.</param> /// <returns>The <see cref="Diagnostic"/> instance.</returns> public static Diagnostic Create( DiagnosticDescriptor descriptor, Location location, ReportDiagnostic effectiveSeverity, IEnumerable <Location> additionalLocations, ImmutableDictionary <string, string> properties, params object[] messageArgs) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } LocalizableString message; if (messageArgs == null || messageArgs.Length == 0) { message = descriptor.MessageFormat; } else { message = new LocalizableStringWithArguments(descriptor.MessageFormat, messageArgs); } var warningLevel = effectiveSeverity.ToDiagnosticSeverity() ?? descriptor.DefaultSeverity; return(Diagnostic.Create( descriptor.Id, descriptor.Category, message, effectiveSeverity.ToDiagnosticSeverity() ?? descriptor.DefaultSeverity, descriptor.DefaultSeverity, descriptor.IsEnabledByDefault, warningLevel: effectiveSeverity.WithDefaultSeverity(descriptor.DefaultSeverity) == ReportDiagnostic.Error ? 0 : 1, effectiveSeverity == ReportDiagnostic.Suppress, descriptor.Title, descriptor.Description, descriptor.HelpLinkUri, location, additionalLocations, descriptor.CustomTags, properties)); }