Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF0005 false positive #262

Open
brian-reichle opened this issue Aug 23, 2019 · 2 comments
Open

WPF0005 false positive #262

brian-reichle opened this issue Aug 23, 2019 · 2 comments

Comments

@brian-reichle
Copy link

I'm getting a WPF0005 false positive using WpfAnalyzers 2.4.0.

class Selectable : Control
{
    public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
        nameof(IsSelected),
        typeof(bool),
        typeof(Selectable),
        new PropertyMetadata(new PropertyChangedCallback(OnIsSelectedChanged)));

    public bool IsSelected
    {
        get => (bool)GetValue(IsSelectedProperty);
        set => SetValue(IsSelectedProperty, value);
    }

    static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        var control = (Selectable)d;

        if ((bool)e.NewValue)
        {
            control.OnSelected();
        }
        else
        {
            control.OnUnseected();
        }
    }

    protected virtual void OnUnseected() // <-- WPF0005: Method 'OnUnselected' should be named 'OnIsSelectedChanged'
    {
    }

    protected virtual void OnSelected() // <-- WPF0005: Method 'OnSelected' should be named 'OnIsSelectedChanged'
    {
    }
}

Extracting 'if' block to another method seems to resolve the issue, so I'm not particularly concerned by it, just thought I should raise the issue in case you wanted to do something about it.

@JohanLarsson
Copy link
Collaborator

Ugh, I'm so terrible, thought I fixed this 🙂, thanks for reporting!
Much appreciated that you updated fast and provide fast and awesome feedback, nice to fix while some things are still in memory.

@JohanLarsson
Copy link
Collaborator

Wonder what the best fix is here, maybe no nag if more than one invocation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants