Skip to content

Update BL0007 warning to explain why a parameter should be an auto-property and what to do #51372

Open

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Also raised:

I got this warning here:
image

I was confused because the hint that something can be made an auto property usually only happens if there is no logic in the get/set. That isn't the case here, and it turns out that is by design.

The comment here by @SteveSandersonMS explains why this rule exists and what the right pattern is for apps that want logic to run on parameter change. However, the message given to the developer doesn't have any of this useful information. The code analysis text needs to be more descriptive and have a link to documentation that shows the right pattern.

The code analysis warning shouldn't require googling to figure out why it happened and how to fix it.

There are lots of comments and upvotes of developers running into this warning here.

Expected Behavior

More detail. A link to documentation with the right pattern.

Steps To Reproduce

[Parameter, EditorRequired]
public required List<DimensionScope> MatchedDimensions
{
    get => _matchedDimensions;
    set
    {
        if (_matchedDimensions != value)
        {
            _matchedDimensions = value;
            _dimensionsOrDurationChanged = true;
        }
    }
}

Exceptions (if any)

No response

.NET Version

.NET 8

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Pillar: Dev ExperiencePriority:2Work that is important, but not critical for the releaseanalyzerIndicates an issue which is related to analyzer experiencearea-blazorIncludes: Blazor, Razor Componentstask

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions