GD0104.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. GD0104: The exported property is write-only
  2. ===========================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0104
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Non-breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A write-only property is annotated with the ``[Export]`` attribute. Write-only properties
  14. can't be exported.
  15. Rule description
  16. ----------------
  17. Godot doesn't allow exporting write-only properties.
  18. .. code-block:: csharp
  19. private int _backingField;
  20. // Write-only properties can't be exported.
  21. [Export]
  22. public int InvalidProperty { set => _backingField = value; }
  23. // This property can be exported because it has both a getter and a setter.
  24. [Export]
  25. public int ValidProperty { get; set; }
  26. How to fix violations
  27. ---------------------
  28. To fix a violation of this rule, make sure the property declares
  29. both a getter and a setter, or remove the ``[Export]`` attribute.
  30. When to suppress warnings
  31. -------------------------
  32. Do not suppress a warning from this rule. Write-only members can't be exported so
  33. they will be ignored by Godot, resulting in runtime errors.