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

INPC001 should not trigger for properties decorated with [Bindable(false)] #172

Open
Insire opened this issue Feb 9, 2020 · 8 comments
Open

Comments

@Insire
Copy link

Insire commented Feb 9, 2020

The analyzer should respect BindableAttribute

grafik

@JohanLarsson
Copy link
Collaborator

Derp, forgot that one, thanks for reporting.

@Insire
Copy link
Author

Insire commented Feb 10, 2020

When fixing this, could you also respect [Bindable(false)] on the class lvl? That way i can remove all the attributes on the properties. It would also be more clear

@jnm2
Copy link
Collaborator

jnm2 commented Feb 16, 2020

When fixing this, could you also respect [Bindable(false)] on the class lvl?

It seems like you're treating [Bindable(false)] as a suppression. A #pragma warning disable for the file is more clear and fits with the way other suppressions work.

@JohanLarsson
Copy link
Collaborator

JohanLarsson commented Feb 16, 2020

It still makes sense for the analyzer to pick up on this attribute.
But I agree that #pragma is preferable if the only goal is to suppress.

@Insire
Copy link
Author

Insire commented Feb 17, 2020

I wanna make it obvious how the class is supposed to be used and in my opinion the BindableAttribute does just that.

I view disabling warnings as a last resort effort to get a desired result.

@jnm2
Copy link
Collaborator

jnm2 commented Feb 17, 2020

Part of my hesitation is that Browsable is an explicitly design-time-only attribute. This seems to back up my intuition that [Browsable(false)] means no more, no less than "hide this property from the designer":

❌ Caution
You can use this attribute at design time only. Nothing prevents you from binding to any property during run time.

https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.bindableattribute#remarks

I would expect non-browsable mutable properties to raise PropertyChanged in some cases just as likely as not.

@Insire
Copy link
Author

Insire commented Feb 17, 2020

Part of my hesitation is that Browsable is an explicitly design-time-only attribute.

The analyzer is a design time only functionality aswell. So anything designtime only is as valid as anything else.

A little bit above that warning it says:

If Bindable is No, you can still bind to the property, but it should not be shown in the default set of properties to bind to, because it might or might not raise a property change notification.

this part in particular captures my opinion quite well:

because it might or might not raise a property change notification.

I would expect non-browsable mutable properties to raise PropertyChanged in some cases just as likely as not.

Yea, our expectations diverge here.

@jnm2
Copy link
Collaborator

jnm2 commented Feb 17, 2020

Sounds like my expectation is almost word-for-word the docs quote there 😁 which means, analyzer shouldn't warn because either way is valid.

I don't think the designer or the docs address the awkward fact that it has AttributeTargets.All, but it seems a little out there to apply it to the class as a suppression unless there are other existing tools that follow the same logic. The analyzer should match somewhat to the real world.

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

3 participants