As part of issue #62644 we fixed compile errors with using ref or in.
But for out usage, we would need to add a diagnostic that explains out usage is not supported for LoggerMessageAttribute annotated logging methods.
Proposal
The proposed diagnostic descriptor would be:
public static DiagnosticDescriptor InvalidLoggingMethodParameterOut { get; } = new DiagnosticDescriptor(
id: "SYSLIB1024",
title: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterOutTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterOutMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
DiagnosticSeverity.Error,
isEnabledByDefault: true);
With the following title:
Argument is using the unsupported out parameter modifier
And the following message format:
Argument '{0}' is using the unsupported out parameter modifier
Code Sample
IReadOnlyList<Diagnostic> diagnostics = await RunGenerator(@$"
partial class C
{{
[LoggerMessage(EventId = 0, Level = LogLevel.Debug, Message = ""Parameter {{P1}}"")]
static partial void M(ILogger logger, out int p1);
}}");
Assert.Single(diagnostics);
Assert.Equal(DiagnosticDescriptors.InvalidLoggingMethodParameterOut.Id, diagnostics[0].Id);
TODO:
As part of issue #62644 we fixed compile errors with using
reforin.But for
outusage, we would need to add a diagnostic that explainsoutusage is not supported forLoggerMessageAttributeannotated logging methods.Proposal
The proposed diagnostic descriptor would be:
With the following title:
And the following message format:
Code Sample
TODO: