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...
GD0002:包含从 GodotObject 派生的嵌套类的类型声明中缺少 partial 修饰符
规则 ID |
GD0002 |
类别 |
用法 |
修复是破坏性的还是非破坏性的 |
非破坏性的 |
默认启用 |
是 |
原因
从 GodotObject
派生的类型包含在非 partial 类型声明中。
规则说明
Godot 源生成器将生成的代码添加到用户定义的类型以实现与引擎的集成。源生成器无法将生成的代码添加到未声明为 partial 的类型。
public class InvalidParentType
{
// MyNode is contained in a non-partial type so the source generators
// can't enhance this type to work with Godot.
public partial class MyNode : Node { }
}
public partial class ValidParentType
{
// MyNode is contained in a partial type so the source generators
// can enhance this type to work with Godot.
public partial class MyNode : Node { }
}
如何解决违规情况
要修复违反该规则的情况,请将 partial
关键字添加到类型声明中。
何时抑制警告
不要抑制该规则的警告。从 GodotObject
派生但不是 partial 的类型无法通过源生成器进行增强,从而导致意外的运行时错误。