GD0111: The exported tool button must be an expression-bodied property
規則 ID |
GD0111 |
分類 |
用法 |
修正是否會破壞相容性 |
非破壞性 |
預設啟用 |
是 |
原因
A property is annotated with the [ExportToolButton] attribute but it's not
an expression-bodied property.
規則說明
When reloading the .NET assembly, Godot will attempt to serialize exported
members to preserve their values. A field or a property with a backing field
that stores a Callable may prevent the unloading of the assembly.
An expression-bodied property doesn't have a backing field and won't store
the Callable, so Godot won't attempt to serialize it, which should result
in the successful reloading of the .NET assembly.
[ExportToolButton("Click me!")]
public Callable ValidClickMeButton => Callable.From(ClickMe);
// Invalid because the Callable will be stored in the property's backing field.
[ExportToolButton("Click me!")]
public Callable InvalidClickMeButton { get; } = Callable.From(ClickMe);
修正方式
To fix a violation of this rule, replace the property implementation with an expression-bodied property.
什麼時候應該忽略警告
Do not suppress a warning from this rule. Callable instances may prevent
the .NET assembly from unloading.