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