refactor(assets): 移除IAssetCatalogSystem接口中的异常文档注释

- 移除RegisterSceneUnit方法的InvalidOperationException异常文档
- 移除RegisterScenePage方法的InvalidOperationException异常文档
- 为SourceGenerators.Abstractions项目启用可空引用类型支持
- 在测试中禁用GF_Common_Trace_001诊断警告
This commit is contained in:
GwWuYou 2025-12-28 16:41:40 +08:00
parent 8b42c6c005
commit 539d285faa
4 changed files with 19 additions and 36 deletions

View File

@ -34,14 +34,12 @@ public interface IAssetCatalogSystem : ISystem
/// </summary> /// </summary>
/// <param name="key">场景单元的唯一标识键</param> /// <param name="key">场景单元的唯一标识键</param>
/// <param name="path">场景单元资源的路径</param> /// <param name="path">场景单元资源的路径</param>
/// <exception cref="InvalidOperationException">当指定的键已存在时抛出异常</exception>
public void RegisterSceneUnit(string key, string path); public void RegisterSceneUnit(string key, string path);
/// <summary> /// <summary>
/// 通过资产目录映射注册场景单元 /// 通过资产目录映射注册场景单元
/// </summary> /// </summary>
/// <param name="mapping">包含场景单元信息的资产目录映射对象</param> /// <param name="mapping">包含场景单元信息的资产目录映射对象</param>
/// <exception cref="InvalidOperationException">当映射ID不是SceneUnitId类型或键已存在时抛出异常</exception>
public void RegisterSceneUnit(AssetCatalog.AssetCatalogMapping mapping); public void RegisterSceneUnit(AssetCatalog.AssetCatalogMapping mapping);
/// <summary> /// <summary>
@ -49,14 +47,12 @@ public interface IAssetCatalogSystem : ISystem
/// </summary> /// </summary>
/// <param name="key">场景页面的唯一标识键</param> /// <param name="key">场景页面的唯一标识键</param>
/// <param name="path">场景页面资源路径</param> /// <param name="path">场景页面资源路径</param>
/// <exception cref="InvalidOperationException">当键已存在时抛出异常</exception>
void RegisterScenePage(string key, string path); void RegisterScenePage(string key, string path);
/// <summary> /// <summary>
/// 通过资产目录映射注册场景页面 /// 通过资产目录映射注册场景页面
/// </summary> /// </summary>
/// <param name="mapping">包含场景页面信息的资产目录映射对象</param> /// <param name="mapping">包含场景页面信息的资产目录映射对象</param>
/// <exception cref="InvalidOperationException">当映射ID不是ScenePageId类型或键已存在时抛出异常</exception>
void RegisterScenePage(AssetCatalog.AssetCatalogMapping mapping); void RegisterScenePage(AssetCatalog.AssetCatalogMapping mapping);
/// <summary> /// <summary>

View File

@ -8,6 +8,7 @@
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<MeziantouPolyfill_IncludedPolyfills>T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute</MeziantouPolyfill_IncludedPolyfills> <MeziantouPolyfill_IncludedPolyfills>T:System.Diagnostics.CodeAnalysis.NotNullWhenAttribute</MeziantouPolyfill_IncludedPolyfills>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<!-- 引入必要的命名空间 --> <!-- 引入必要的命名空间 -->

View File

@ -25,7 +25,8 @@ public static class GeneratorTest<TGenerator>
TestState = TestState =
{ {
Sources = { source } Sources = { source }
} },
DisabledDiagnostics = { "GF_Common_Trace_001" }
}; };
// 添加期望的生成源文件到测试状态中 // 添加期望的生成源文件到测试状态中

View File

@ -4,18 +4,11 @@ using NUnit.Framework;
namespace GFramework.SourceGenerators.Tests.rule; namespace GFramework.SourceGenerators.Tests.rule;
/// <summary>
/// 测试ContextAwareGenerator源代码生成器的功能
/// </summary>
[TestFixture] [TestFixture]
public class ContextAwareGeneratorTests public class ContextAwareGeneratorTests
{ {
/// <summary>
/// 测试ContextAware代码生成功能
/// 验证当使用[ContextAware]特性标记的类能够正确生成上下文感知的相关代码
/// </summary>
[Test] [Test]
public Task Generates_ContextAware_Code() public async Task Generates_ContextAware_Code()
{ {
const string source = """ const string source = """
using System; using System;
@ -33,7 +26,8 @@ public class ContextAwareGeneratorTests
using GFramework.SourceGenerators.Abstractions.rule; using GFramework.SourceGenerators.Abstractions.rule;
[ContextAware] [ContextAware]
public partial class MyRule: GFramework.Core.Abstractions.rule.IContextAware public partial class MyRule
: GFramework.Core.Abstractions.rule.IContextAware
{ {
} }
} }
@ -44,7 +38,8 @@ public class ContextAwareGeneratorTests
{ {
public interface IContextAware public interface IContextAware
{ {
void SetContext(GFramework.Core.Abstractions.architecture.IArchitectureContext context); void SetContext(
GFramework.Core.Abstractions.architecture.IArchitectureContext context);
} }
} }
@ -75,19 +70,14 @@ public class ContextAwareGeneratorTests
} }
"""; """;
Assert.DoesNotThrowAsync(async () => await GeneratorTest<ContextAwareGenerator>.RunAsync(
{ source + "\n" + frameworkStub,
await GeneratorTest<ContextAwareGenerator>.RunAsync( ("MyRule.ContextAware.g.cs", expected)
source + "\n" + frameworkStub, );
("MyRule.ContextAware.g.cs", expected)
);
});
return Task.CompletedTask;
} }
[Test] [Test]
public Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware() public async Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
{ {
const string source = """ const string source = """
using System; using System;
@ -105,7 +95,6 @@ public class ContextAwareGeneratorTests
using GFramework.SourceGenerators.Abstractions.rule; using GFramework.SourceGenerators.Abstractions.rule;
using GFramework.Core.Abstractions.rule; using GFramework.Core.Abstractions.rule;
// 间接接口:继承自 IContextAware
public interface IMyRuleContextAware : IContextAware public interface IMyRuleContextAware : IContextAware
{ {
} }
@ -122,7 +111,8 @@ public class ContextAwareGeneratorTests
{ {
public interface IContextAware public interface IContextAware
{ {
void SetContext(GFramework.Core.Abstractions.architecture.IArchitectureContext context); void SetContext(
GFramework.Core.Abstractions.architecture.IArchitectureContext context);
} }
} }
@ -153,14 +143,9 @@ public class ContextAwareGeneratorTests
} }
"""; """;
Assert.DoesNotThrowAsync(async () => await GeneratorTest<ContextAwareGenerator>.RunAsync(
{ source + "\n" + frameworkStub,
await GeneratorTest<ContextAwareGenerator>.RunAsync( ("MyRule.ContextAware.g.cs", expected)
source + "\n" + frameworkStub, );
("MyRule.ContextAware.g.cs", expected)
);
});
return Task.CompletedTask;
} }
} }