GeWuYou 5b996d8618 feat(generator): 添加 BindNodeSignal 源生成器实现
- 实现 BindNodeSignalGenerator 源生成器,用于自动生成 Godot 节点事件绑定与解绑逻辑
- 添加 BindNodeSignalAttribute 特性,标记需要生成绑定逻辑的事件处理方法
- 实现完整的诊断系统,包括嵌套类型、静态方法、字段类型等错误检查
- 添加生命周期方法调用检查,在 _Ready 和 _ExitTree 中验证生成方法的调用
- 支持方法签名与事件委托的兼容性验证
- 实现单元测试覆盖各种使用场景和错误情况
2026-03-31 09:39:06 +08:00

40 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#nullable enable
namespace GFramework.Godot.SourceGenerators.Abstractions;
/// <summary>
/// 标记 Godot 节点事件处理方法Source Generator 会为其生成事件绑定与解绑逻辑。
/// </summary>
/// <remarks>
/// 该特性通过节点字段名与事件名建立声明式订阅关系,适用于将
/// <c>_Ready()</c> / <c>_ExitTree()</c> 中重复的 <c>+=</c> 与 <c>-=</c> 样板代码
/// 收敛到生成器中统一维护。
/// </remarks>
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]
public sealed class BindNodeSignalAttribute : Attribute
{
/// <summary>
/// 初始化 <see cref="BindNodeSignalAttribute" /> 的新实例。
/// </summary>
/// <param name="nodeFieldName">目标节点字段名。</param>
/// <param name="signalName">目标节点上的 CLR 事件名。</param>
/// <exception cref="ArgumentNullException">
/// <paramref name="nodeFieldName" /> 或 <paramref name="signalName" /> 为 <see langword="null" />。
/// </exception>
public BindNodeSignalAttribute(
string nodeFieldName,
string signalName)
{
NodeFieldName = nodeFieldName ?? throw new ArgumentNullException(nameof(nodeFieldName));
SignalName = signalName ?? throw new ArgumentNullException(nameof(signalName));
}
/// <summary>
/// 获取目标节点字段名。
/// </summary>
public string NodeFieldName { get; }
/// <summary>
/// 获取目标节点上的 CLR 事件名。
/// </summary>
public string SignalName { get; }
}