GD0103.rst 1.7 KB

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