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...
GD0201:委派的名稱必須以 'EventHandler' 結尾
規則 ID |
GD0201 |
分類 |
用法 |
修正是否會破壞相容性 |
破壞性變更 |
預設啟用 |
是 |
原因
使用 [Signal] 屬性標註的委派名稱未以 'EventHandler' 結尾。
規則說明
Godot 的原始碼產生器會以移除 'EventHandler' 字尾後的委派名稱來產生 C# 事件。在事件使用的委派上加上 'EventHandler' 字尾是 .NET 的命名慣例,詳見 .NET 命名慣例。
為委派加上字尾,可以讓產生的事件自動移除該字尾,避免與其他名稱衝突。
// This delegate is invalid since the name doesn't end with 'EventHandler'.
[Signal]
public void InvalidSignal();
// This delegate is valid since the name ends with 'EventHandler'.
[Signal]
public void ValidSignalEventHandler();
請參閱 C# 訊號 文件,瞭解如何宣告與使用訊號。
修正方式
要修正此規則的違規情形,請在委派名稱最後加上 'EventHandler'。
什麼時候應該忽略警告
請勿忽略此規則的警告。沒有加上字尾的委派會被原始碼產生器忽略,訊號將不會被註冊。