GD0111.rst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. GD0111: The exported tool button must be an expression-bodied property
  2. ======================================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0111
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Non-breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A property is annotated with the ``[ExportToolButton]`` attribute but it's not
  14. an `expression-bodied property`_.
  15. Rule description
  16. ----------------
  17. When reloading the .NET assembly, Godot will attempt to serialize exported
  18. members to preserve their values. A field or a property with a backing field
  19. that stores a ``Callable`` may prevent the unloading of the assembly.
  20. An expression-bodied property doesn't have a backing field and won't store
  21. the ``Callable``, so Godot won't attempt to serialize it, which should result
  22. in the successful reloading of the .NET assembly.
  23. .. code-block:: csharp
  24. [ExportToolButton("Click me!")]
  25. public Callable ValidClickMeButton => Callable.From(ClickMe);
  26. // Invalid because the Callable will be stored in the property's backing field.
  27. [ExportToolButton("Click me!")]
  28. public Callable InvalidClickMeButton { get; } = Callable.From(ClickMe);
  29. How to fix violations
  30. ---------------------
  31. To fix a violation of this rule, replace the property implementation with an
  32. `expression-bodied property`_.
  33. When to suppress warnings
  34. -------------------------
  35. Do not suppress a warning from this rule. ``Callable`` instances may prevent
  36. the .NET assembly from unloading.
  37. .. _expression-bodied property: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members#properties