CSharpGuidelinesAnalyzer
CSharpGuidelinesAnalyzer copied to clipboard
AV1553: Suppress on CallerArgumentExpressions
Analyzer
AV1553: DoNotUseOptionalParameterWithDefaultValueNullAnalyzer
Repro steps
#nullable enable
internal static class ArgumentGuard
{
public static void NotNull<T>(T? value, [CallerArgumentExpression("value")] string? parameterName = null)
where T : class
{
ArgumentNullException.ThrowIfNull(value, parameterName);
}
}
Expected behavior
No warning on parameterName
, because the purpose of using CallerArgumentExpression
is an optional string, which is filled in by the C# compiler. Using a non-nullable parameterName
or removing the default value or null
causes errors/warnings on the use of this attribute.
Actual behavior
Warning AV1553: Optional parameter 'parameterName' of type 'string' has default value 'null'