From 0126b69c5ceae6dd601f8373920f2bd8d4ef8410 Mon Sep 17 00:00:00 2001 From: GwWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 27 Dec 2025 22:18:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor(source-generators):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E6=BA=90=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E5=99=A8?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=E5=92=8C=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 IArchitectureExtensible 接口定义 - 更新 Godot 源代码生成器项目配置,添加 Nullable 启用和包路径配置 - 添加 Directory.Build.props 构建属性文件到抽象层项目 - 修复命名空间引用错误和添加 using 语句 - 优化源代码生成器项目的打包配置和依赖引用 - 添加文档注释到 LogAttribute 构造函数 - 更新主项目文件中的源代码生成器相关引用路径 - 从解决方案用户设置中移除过时配置文件 - 添加解决方案用户设置到 gitignore 文件 --- .gitignore | 3 +- .../architecture/IArchitectureExtensible.cs | 19 ---------- .../Directory.Build.props | 26 +++++++++++++ ...Godot.SourceGenerators.Abstractions.csproj | 16 +++++--- .../logging/GodotLogAttribute.cs | 5 ++- .../GFramework.Godot.SourceGenerators.csproj | 37 ++++++++++++++----- .../Directory.Build.props | 24 ++++++++++++ ...ework.SourceGenerators.Abstractions.csproj | 17 ++++++--- .../enums/EnumExtensionsAttribute.cs | 4 +- .../logging/LogAttribute.cs | 8 +++- .../rule/ContextAwareAttribute.cs | 4 +- .../Directory.Build.props | 23 ++++++++++++ .../GFramework.SourceGenerators.Common.csproj | 5 ++- .../GFramework.SourceGenerators.Tests.csproj | 1 - .../GFramework.SourceGenerators.csproj | 26 +++++++++++-- .../logging/LoggerGenerator.cs | 5 +-- GFramework.csproj | 15 +++----- GFramework.sln.DotSettings.user | 17 --------- 18 files changed, 173 insertions(+), 82 deletions(-) delete mode 100644 GFramework.Core/architecture/IArchitectureExtensible.cs create mode 100644 GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props create mode 100644 GFramework.SourceGenerators.Abstractions/Directory.Build.props create mode 100644 GFramework.SourceGenerators.Common/Directory.Build.props delete mode 100644 GFramework.sln.DotSettings.user diff --git a/.gitignore b/.gitignore index add57be..ba56cfd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ bin/ obj/ /packages/ riderModule.iml -/_ReSharper.Caches/ \ No newline at end of file +/_ReSharper.Caches/ +GFramework.sln.DotSettings.user \ No newline at end of file diff --git a/GFramework.Core/architecture/IArchitectureExtensible.cs b/GFramework.Core/architecture/IArchitectureExtensible.cs deleted file mode 100644 index 1fd93a7..0000000 --- a/GFramework.Core/architecture/IArchitectureExtensible.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace GFramework.Core.architecture; - -/// -/// 可扩展架构接口,继承自IArchitecture接口,提供模块安装和生命周期钩子注册功能 -/// -public interface IArchitectureExtensible : IArchitecture -{ - /// - /// 安装架构模块 - /// - /// 要安装的架构模块实例 - void InstallModule(IArchitectureModule module); - - /// - /// 注册架构生命周期钩子 - /// - /// 要注册的架构生命周期钩子实例 - void RegisterLifecycleHook(IArchitectureLifecycle hook); -} \ No newline at end of file diff --git a/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props b/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props new file mode 100644 index 0000000..3a9b545 --- /dev/null +++ b/GFramework.Godot.SourceGenerators.Abstractions/Directory.Build.props @@ -0,0 +1,26 @@ + + + + netstandard2.0 + true + true + + preview + + + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj index 3d2751f..3e7de14 100644 --- a/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj +++ b/GFramework.Godot.SourceGenerators.Abstractions/GFramework.Godot.SourceGenerators.Abstractions.csproj @@ -1,11 +1,17 @@  + - netstandard2.0 - GeWuYou.GFramework.Godot.SourceGenerators.Attributes - 1.0.0 - 10 - GFramework.Godot.SourceGenerators.Attributes + false + true + T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute + + + + diff --git a/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs b/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs index a3b2b92..2de1603 100644 --- a/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs +++ b/GFramework.Godot.SourceGenerators.Abstractions/logging/GodotLogAttribute.cs @@ -1,5 +1,6 @@ -#nullable enable -namespace GFramework.GFramework.Godot.SourceGenerators.Abstractions.logging; +using System; + +namespace GFramework.Godot.SourceGenerators.Abstractions.logging; /// /// Godot日志特性,用于在类上标记以自动生成日志字段 diff --git a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj index db5e1fd..f5268a0 100644 --- a/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj +++ b/GFramework.Godot.SourceGenerators/GFramework.Godot.SourceGenerators.csproj @@ -4,39 +4,58 @@ GeWuYou.GFramework.Godot.SourceGenerators netstandard2.0 - + true false latest + enable true Generated - + - + + all + runtime; build; native; contentfiles; analyzers + - + - - + + - + - + + + + + + + + + + diff --git a/GFramework.SourceGenerators.Abstractions/Directory.Build.props b/GFramework.SourceGenerators.Abstractions/Directory.Build.props new file mode 100644 index 0000000..82f43af --- /dev/null +++ b/GFramework.SourceGenerators.Abstractions/Directory.Build.props @@ -0,0 +1,24 @@ + + + + netstandard2.0 + true + true + + preview + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj b/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj index 17d60c6..f7470af 100644 --- a/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj +++ b/GFramework.SourceGenerators.Abstractions/GFramework.SourceGenerators.Abstractions.csproj @@ -1,12 +1,17 @@  + + - netstandard2.0 - GeWuYou.GFramework.SourceGenerators.Attributes - 1.0.0 - 10 - GFramework.SourceGenerators.Attributes + false + true + T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute + + - + diff --git a/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs b/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs index 3fca257..8c7a47f 100644 --- a/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/enums/EnumExtensionsAttribute.cs @@ -1,4 +1,6 @@ -namespace GFramework.GFramework.SourceGenerators.Abstractions.enums; +using System; + +namespace GFramework.SourceGenerators.Abstractions.enums; /// /// 标注在 enum 上,Source Generator 会为该 enum 生成扩展方法。 diff --git a/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs b/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs index 6256089..52e7325 100644 --- a/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/logging/LogAttribute.cs @@ -1,5 +1,7 @@ #nullable enable -namespace GFramework.GFramework.SourceGenerators.Abstractions.logging; +using System; + +namespace GFramework.SourceGenerators.Abstractions.logging; /// /// 标注在类上,Source Generator 会为该类自动生成一个日志记录器字段。 @@ -7,6 +9,9 @@ namespace GFramework.GFramework.SourceGenerators.Abstractions.logging; [AttributeUsage(AttributeTargets.Class, Inherited = false)] public sealed class LogAttribute : Attribute { + /// + /// 初始化 LogAttribute 类的新实例 + /// public LogAttribute() { } @@ -20,6 +25,7 @@ public sealed class LogAttribute : Attribute Name = name; } + /// 日志分类名(默认使用类名) public string? Name { get; set; } diff --git a/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs b/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs index 433c16f..d1060d0 100644 --- a/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs +++ b/GFramework.SourceGenerators.Abstractions/rule/ContextAwareAttribute.cs @@ -1,4 +1,6 @@ -namespace GFramework.GFramework.SourceGenerators.Abstractions.rule; +using System; + +namespace GFramework.SourceGenerators.Attributes.rule; /// /// 标记该类需要自动实现 IContextAware diff --git a/GFramework.SourceGenerators.Common/Directory.Build.props b/GFramework.SourceGenerators.Common/Directory.Build.props new file mode 100644 index 0000000..016f796 --- /dev/null +++ b/GFramework.SourceGenerators.Common/Directory.Build.props @@ -0,0 +1,23 @@ + + + netstandard2.0 + true + true + + preview + + + + all + runtime; build; native; contentfiles; analyzers + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj b/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj index 20d6f77..a1c3b5b 100644 --- a/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj +++ b/GFramework.SourceGenerators.Common/GFramework.SourceGenerators.Common.csproj @@ -1,8 +1,9 @@  - netstandard2.0 - 10 + false + true + T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute diff --git a/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj b/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj index ec7d901..911926f 100644 --- a/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj +++ b/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj @@ -10,7 +10,6 @@ - diff --git a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj index eee4406..2f35e22 100644 --- a/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj +++ b/GFramework.SourceGenerators/GFramework.SourceGenerators.csproj @@ -19,25 +19,43 @@ - + + all + runtime; build; native; contentfiles; analyzers + - + - + + + + + + + + + + diff --git a/GFramework.SourceGenerators/logging/LoggerGenerator.cs b/GFramework.SourceGenerators/logging/LoggerGenerator.cs index 5d931c0..a6d0ba1 100644 --- a/GFramework.SourceGenerators/logging/LoggerGenerator.cs +++ b/GFramework.SourceGenerators/logging/LoggerGenerator.cs @@ -1,7 +1,4 @@ -#nullable enable - - -using System; +using System; using System.Linq; using System.Text; using GFramework.SourceGenerators.Common.diagnostics; diff --git a/GFramework.csproj b/GFramework.csproj index 2ea6e5e..bbdeb31 100644 --- a/GFramework.csproj +++ b/GFramework.csproj @@ -24,9 +24,6 @@ - - GFramework.SorceGenerators\bin\Debug\netstandard2.0\GFramework.Generator.Attributes.dll - GFramework.SorceGenerators\logging\README.md @@ -40,12 +37,12 @@ GFramework.SorceGenerators\AnalyzerReleases.Unshipped.md - - + + @@ -66,24 +63,24 @@ GFramework.SorceGenerators\logging\LoggerGenerator.cs - - + + - - + + diff --git a/GFramework.sln.DotSettings.user b/GFramework.sln.DotSettings.user deleted file mode 100644 index 444ecc6..0000000 --- a/GFramework.sln.DotSettings.user +++ /dev/null @@ -1,17 +0,0 @@ - - ForceIncluded - ForceIncluded - ForceIncluded - ForceIncluded - ForceIncluded - ForceIncluded - <SessionState ContinuousTestingMode="0" IsActive="True" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <TestAncestor> - <TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId> - </TestAncestor> -</SessionState> - <SessionState ContinuousTestingMode="0" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"> - <TestAncestor> - <TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId> - </TestAncestor> -</SessionState> \ No newline at end of file