Code inspection with refactoring

Answered

I'm trying to combine a Search with Pattern code inspection with a refactoring. More precise, I want to:

1. detect fields that are public but could be made private (and add a Quick Fix menu option for it).

2. refactor the field so its private and renamed properly (_fieldName instead of FieldName).

3. Add attribute based on the former name, e.g. [MyAttribute("FieldName")]

Can this be achieved directly with existing ReSharper functionality? Or would I need to create a Declarative Extension?

Thanks!

0
1 comment

This would require a full plugin, rather than using existing functionality or a structural search pattern. Checking to see if a public field is unused is already done when Solution Wide Error Analysis is enabled, which tracks usage between classes. You'd be able to attach a quick fix to a globally unused field warning which could encapsulate the field and add the attribute. You might be able to reuse the existing encapsulate field refactoring here, and then just add the attribute afterwards.

0

Please sign in to leave a comment.