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.

GD0103:被匯出的成員為唯讀(read-only)

規則 ID

GD0103

分類

用法

修正是否會破壞相容性

非破壞性

預設啟用

原因

唯讀成員被標註為 [Export]。唯讀成員無法被匯出。

規則說明

Godot 不允許匯出唯讀成員。

// Read-only fields can't be exported.
[Export]
public readonly int invalidField;

// This field can be exported because it's not declared 'readonly'.
[Export]
public int validField;

// Read-only properties can't be exported.
[Export]
public int InvalidProperty { get; }

// This property can be exported because it has both a getter and a setter.
[Export]
public int ValidProperty { get; set; }

修正方式

要修正欄位違規,請移除 readonly 關鍵字或 [Export] 屬性。

要修正屬性違規,請確保該屬性同時有 getter 與 setter,或移除 [Export] 屬性。

什麼時候應該忽略警告

請勿忽略此規則的警告。唯讀成員無法被匯出,Godot 會忽略該成員,造成執行階段錯誤。