GD0104:导出的属性是只写的
规则 ID |
GD0104 |
类别 |
用法 |
修复是破坏性的还是非破坏性的 |
非破坏性的 |
默认启用 |
是 |
原因
只写属性用 [Export]
属性注解。只写属性无法被导出。
规则说明
Godot 不允许导出只写属性。
private int _backingField;
// Write-only properties can't be exported.
[Export]
public int InvalidProperty { set => _backingField = value; }
// This property can be exported because it has both a getter and a setter.
[Export]
public int ValidProperty { get; set; }
如何解决违规情况
要修复违反该规则的情况,请确保属性同时声明了 getter 和 setter,或者移除 [Export]
属性。
何时抑制警告
不要抑制该规则的警告。只写成员无法被导出,因此它们将被 Godot 忽略,从而导致运行时错误。