Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
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 會忽略該成員,造成執行階段錯誤。