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

Inspection for (mis)usage of module fields backed by property #3589

Open
bclothier opened this issue Dec 4, 2017 · 1 comment
Open

Inspection for (mis)usage of module fields backed by property #3589

bclothier opened this issue Dec 4, 2017 · 1 comment
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections

Comments

@bclothier
Copy link
Contributor

Given this code:

Private BackingField As String

Public Property Get Field() As String
  Field = BackingField
End Property

Public Property Let(NewValue As String)
  'Some complicated logic goes here...
  BackingField = NewValue
End Property

Public Sub Doh()
  BackingField = "Bypassing the logic!"
End Sub

It's too easy to wrongly reference the backing field within the module; there are instances where bypassing the logic embedded in the setter is fine, but I think it'd be good to have an inspection to bring attention of this possible oversight, so an explicit choice can be made whether it's intended to bypass the setter's logic or not. Given this isn't an error per se, the inspection would be a suggestion, or warning.

This also implies a need for the @IgnoreOnce annotation with a comment to make it clear we are deliberately assigning to the backing field.

@Vogel612 Vogel612 added enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections labels Dec 4, 2017
@Hosch250
Copy link
Member

Hosch250 commented Dec 4, 2017

Brilliant idea. The IgnoreOnce attribute should automatically work, but it would be something we need to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests, or enhancements to existing features. Ideas. Anything within the project's scope. feature-inspections
Projects
None yet
Development

No branches or pull requests

3 participants