JetBrains / JetBrains/resharper-unity
Feature request: Add [SerializeField] attribute when using Refactor-Encapsulate field on serialized fields
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 142
- PR merge metrics
- No merged PRs in 30d
Description
When using Refactor-Encapsulate with the private field option on public serialized fields in Unity data loss can occur because private fields must be marked for serialization explicitly. Ideally an encapsulation-refactor in resharper-unity should turn this:

Into something like this:

(Depending on what was selected in the refactor dialog window of course, in this case the field was set to private as well.)
Do note that since the name chosen for the property was the same as the field already had, ReSharper has also renamed the backing field to avoid a name collision, in those instances it should also mark the field with a FormerlySerializedAs attribute with the old field-name as an argument, so you would end up with is something like this:

Contributor guide
Assessment
This issue has not been assessed yet.