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

Fix S1104 FP: Do not report in Unity serializable classes #7522

Closed
antonioaversa opened this issue Jun 30, 2023 · 0 comments · Fixed by #9514
Closed

Fix S1104 FP: Do not report in Unity serializable classes #7522

antonioaversa opened this issue Jun 30, 2023 · 0 comments · Fixed by #9514
Assignees
Labels
Area: C# C# rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@antonioaversa
Copy link
Contributor

Derived from this discuss post.

S1104 raises in all contexts, including in Unity scripts derived from MonoBehavior. The rule should not report in that context, however, due to how Unity works.
Using public properties would break core features of Unity such as YAML serialization and UI editing.

Unity requires using public fields, and using public properties would break core features of Unity such as serialization and UI editing.

Unity has specific rules for serialization, detailed here.

Serializers in Unity work directly on the fields of your C# classes rather than their properties, so there are rules that your fields must conform to be serialized.

Notice that there are ways of conforming to S1104 in Unity: as shown in the “Serialization of properties” section of the documentation, user-implemented properties with a backing field marked as SerializeField would be supported by the Unity Editor.

Regardless, those are corner cases that are rarely encountered in practice.

@antonioaversa antonioaversa added Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Jun 30, 2023
@sebastien-marichal sebastien-marichal added the Sprint: Hardening Fix FPs/FNs/improvements label Jul 9, 2024
@sebastien-marichal sebastien-marichal self-assigned this Jul 9, 2024
@sebastien-marichal sebastien-marichal changed the title Fix S1104 FP: Do not report in Unity Monobehavior Fix S1104 FP: Do not report in Unity MonoBehavior Jul 9, 2024
@sebastien-marichal sebastien-marichal changed the title Fix S1104 FP: Do not report in Unity MonoBehavior Fix S1104 FP: Do not report in Unity serializable classes Jul 9, 2024
@sebastien-marichal sebastien-marichal added this to the 9.29 milestone Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Sprint: Hardening Fix FPs/FNs/improvements Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants