Skip to content

AV1553: Suppress on CallerArgumentExpressions #136

@bkoelman

Description

@bkoelman

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions