GD0106:导出的属性是一个显式接口实现

规则 ID

GD0106

类别

用法

修复是破坏性的还是非破坏性的

非破坏性的

默认启用

原因

显式接口属性实现使用 [Export] 属性进行注解。显式实现接口的属性无法被导出。

规则说明

Godot 不允许导出显式接口属性实现。当显式实现接口成员时,该成员将被隐藏,除非先将类型转换为接口,否则使用者无法访问它们。显式实现的成员还可以与类型中的其他成员共享相同的名称,因此可能会与其他导出的成员产生命名冲突。

public interface MyInterface
{
    public int MyProperty { get; set; }
}

public class MyNode1 : Node, MyInterface
{
    // The property can be exported because it implements the interface implicitly.
    [Export]
    public int MyProperty { get; set; }
}

public class MyNode2 : Node, MyInterface
{
    // The property can't be exported because it implements the interface explicitly.
    [Export]
    int MyInterface.MyProperty { get; set; }
}

如何解决违规情况

要修复违反该规则的情况,请隐式实现接口或移除 [Export] 属性。

何时抑制警告

不要抑制该规则的警告。显式接口属性实现无法被导出,因此它们将被 Godot 忽略,从而导致运行时错误。