CSharpGuidelinesAnalyzer icon indicating copy to clipboard operation
CSharpGuidelinesAnalyzer copied to clipboard

AV1553: Suppress on CallerArgumentExpressions

Open bkoelman opened this issue 2 years ago • 0 comments

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'

bkoelman avatar Sep 23 '22 23:09 bkoelman