diff --git a/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj b/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj
index de90d21..ec7d901 100644
--- a/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj
+++ b/GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj
@@ -3,11 +3,13 @@
enable
enable
- net10.0;net8.0;net9.0
+ net8.0
+
+
diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
index 3a70a92..c1b5b37 100644
--- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
+++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
@@ -20,17 +20,27 @@ public class ContextAwareGeneratorTests
{
// 定义输入源代码,包含使用[ContextAware]特性的部分类
const string source = """
- using GFramework.Core.rule;
- using GFramework.Core.architecture;
+ using System;
+
+ namespace GFramework.SourceGenerators.Attributes.rule
+ {
+ [AttributeUsage(AttributeTargets.Class)]
+ public sealed class ContextAwareAttribute : Attribute
+ {
+ }
+ }
namespace TestApp;
+ using GFramework.SourceGenerators.Attributes.rule;
+
[ContextAware]
public partial class MyRule
{
}
""";
+
// 定义期望的生成结果代码
const string expected = """
//
@@ -40,7 +50,6 @@ public class ContextAwareGeneratorTests
partial class MyRule : GFramework.Core.rule.IContextAware
{
protected GFramework.Core.architecture.IArchitectureContext Context { get; private set; } = null!;
-
void GFramework.Core.rule.IContextAware.SetContext(
GFramework.Core.architecture.IArchitectureContext context)
{
@@ -49,6 +58,7 @@ public class ContextAwareGeneratorTests
}
""";
+
// 执行源代码生成器测试
await GeneratorTest.RunAsync(
source,
diff --git a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
index 0fd1cb7..2c2de4f 100644
--- a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
+++ b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
@@ -99,13 +99,12 @@ public sealed class ContextAwareGenerator : IIncrementalGenerator
sb.AppendLine(
" protected GFramework.Core.architecture.IArchitectureContext Context { get; private set; } = null!;");
- sb.AppendLine("""
- void GFramework.Core.rule.IContextAware.SetContext(
- GFramework.Core.architecture.IArchitectureContext context)
- {
- Context = context;
- }
- """);
+ sb.AppendLine(" void GFramework.Core.rule.IContextAware.SetContext(");
+ sb.AppendLine(" GFramework.Core.architecture.IArchitectureContext context)");
+ sb.AppendLine(" {");
+ sb.AppendLine(" Context = context;");
+ sb.AppendLine(" }");
+
sb.AppendLine("}");
diff --git a/GFramework.sln.DotSettings.user b/GFramework.sln.DotSettings.user
index 56537ed..8865a13 100644
--- a/GFramework.sln.DotSettings.user
+++ b/GFramework.sln.DotSettings.user
@@ -1,3 +1,8 @@
ForceIncluded
- ForceIncluded
\ No newline at end of file
+ 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>
\ No newline at end of file