JetBrains / JetBrains/resharper-unity

Feature request: Add [SerializeField] attribute when using Refactor-Encapsulate field on serialized fields

Open
#55 0 comments 3 reactions 0 assignees View on GitHub
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:
![refactorencapsulatebefore](https://cloud.githubusercontent.com/assets/1384288/19541895/75f0c630-966a-11e6-839a-e9e0914a9bc4.png)

Into something like this:
![refactorencapsulateafter](https://cloud.githubusercontent.com/assets/1384288/19541896/77cc48da-966a-11e6-83aa-0d3bd95abf6e.png)
(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:
![refactorencapsulateafter2](https://cloud.githubusercontent.com/assets/1384288/19542063/a96f6736-966b-11e6-8ef6-2c53a9ddbc15.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.