Skip to content
3 changes: 3 additions & 0 deletions GFramework.Core.SourceGenerators/Bases/PriorityGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ protected override string Generate(
? $"<{string.Join(", ", symbol.TypeParameters.Select(tp => tp.Name))}>"
: string.Empty;

sb.AppendLine("/// <summary>");
sb.AppendLine("/// 为当前分部类型补充自动生成的优先级契约实现。");
sb.AppendLine("/// </summary>");
sb.AppendLine(
$"partial class {symbol.Name}{typeParameters} : global::GFramework.Core.Abstractions.Bases.IPrioritized");
sb.AppendLine("{");
Expand Down
19 changes: 17 additions & 2 deletions GFramework.Core.SourceGenerators/Enums/EnumExtensionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ protected override string Generate(INamedTypeSymbol symbol, AttributeData attr)

sb.AppendLine("{");

sb.AppendLine(" /// <summary>");
sb.AppendLine($" /// 为 <see cref=\"{fullEnumName}\" /> 提供自动生成的扩展方法。");
sb.AppendLine(" /// </summary>");
sb.AppendLine($" public static partial class {enumName}Extensions");
sb.AppendLine(" {");

Expand Down Expand Up @@ -176,7 +179,13 @@ private static bool AppendIsMethods(StringBuilder builder, IEnumerable<IFieldSym
builder.AppendLine();
}

builder.AppendLine($" /// <summary>是否为 {memberName}</summary>");
builder.AppendLine(" /// <summary>");
builder.AppendLine(
$" /// 判断给定值是否为 <see cref=\"{fullEnumName}.{memberName}\" />。");
builder.AppendLine(" /// </summary>");
builder.AppendLine(" /// <param name=\"value\">要检查的枚举值。</param>");
builder.AppendLine(
$" /// <returns>当 <paramref name=\"value\" /> 等于 <see cref=\"{fullEnumName}.{memberName}\" /> 时返回 <see langword=\"true\" />;否则返回 <see langword=\"false\" />。</returns>");
builder.AppendLine(
$" public static bool Is{memberName}(this {fullEnumName} value) => value == {fullEnumName}.{memberName};");
hasGeneratedMembers = true;
Expand All @@ -192,7 +201,13 @@ private static bool AppendIsMethods(StringBuilder builder, IEnumerable<IFieldSym
/// <param name="fullEnumName">枚举的完整类型名。</param>
private static void AppendIsInMethod(StringBuilder builder, string fullEnumName)
{
builder.AppendLine(" /// <summary>判断是否属于指定集合</summary>");
builder.AppendLine(" /// <summary>");
builder.AppendLine(" /// 判断给定值是否属于指定候选集合。");
builder.AppendLine(" /// </summary>");
builder.AppendLine(" /// <param name=\"value\">要检查的枚举值。</param>");
builder.AppendLine(" /// <param name=\"values\">用于匹配的候选枚举值集合。</param>");
builder.AppendLine(
" /// <returns>当 <paramref name=\"value\" /> 命中任一候选值时返回 <see langword=\"true\" />;否则返回 <see langword=\"false\" />。</returns>");
builder.AppendLine(
$" public static bool IsIn(this {fullEnumName} value, params {fullEnumName}[] values)");
builder.AppendLine(" {");
Expand Down
7 changes: 6 additions & 1 deletion GFramework.Core.SourceGenerators/Logging/LoggerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ protected override string Generate(
.AppendLine($"namespace {ns};");

sb.AppendLine()
.AppendLine("/// <summary>")
.AppendLine("/// 为当前分部类型提供自动生成的日志字段。")
.AppendLine("/// </summary>")
.AppendLine($"partial {typeKind} {className}{generics.Parameters}");

foreach (var c in generics.Constraints)
sb.AppendLine($" {c}");

sb.AppendLine("{")
.AppendLine(" /// <summary>Auto-generated logger</summary>")
.AppendLine(" /// <summary>")
.AppendLine(" /// 自动生成的日志字段。")
.AppendLine(" /// </summary>")
.AppendLine(
$" {access} {staticKeyword}readonly ILogger {fieldName} = " +
$"LoggerFactoryResolver.Provider.CreateLogger(\"{logName}\");")
Expand Down
28 changes: 22 additions & 6 deletions GFramework.Core.SourceGenerators/Rule/ContextAwareGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ protected override string Generate(

var interfaceName = iContextAware.ToDisplayString(
SymbolDisplayFormat.FullyQualifiedFormat);
sb.AppendLine("/// <summary>");
sb.AppendLine("/// 为当前规则类型补充自动生成的架构上下文访问实现。");
sb.AppendLine("/// </summary>");
sb.AppendLine($"partial class {symbol.Name} : {interfaceName}");
sb.AppendLine("{");

Expand Down Expand Up @@ -128,6 +131,7 @@ private static void GenerateContextProperty(StringBuilder sb)
sb.AppendLine(" private global::GFramework.Core.Abstractions.Architectures.IArchitectureContext? _context;");
sb.AppendLine(
" private static global::GFramework.Core.Abstractions.Architectures.IArchitectureContextProvider? _contextProvider;");
sb.AppendLine(" private static readonly object _contextSync = new();");
sb.AppendLine();
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// 自动获取的架构上下文(懒加载,默认使用 GameContextProvider)");
Expand All @@ -136,14 +140,20 @@ private static void GenerateContextProperty(StringBuilder sb)
sb.AppendLine(" {");
sb.AppendLine(" get");
sb.AppendLine(" {");
sb.AppendLine(" if (_context == null)");
sb.AppendLine(" var context = _context;");
sb.AppendLine(" if (context is not null)");
sb.AppendLine(" {");
sb.AppendLine(" return context;");
sb.AppendLine(" }");
sb.AppendLine();
sb.AppendLine(" // 在同一个同步域内协调懒加载与 provider 切换,避免读取到被并发重置的空提供者。");
sb.AppendLine(" lock (_contextSync)");
sb.AppendLine(" {");
sb.AppendLine(
" _contextProvider ??= new global::GFramework.Core.Architectures.GameContextProvider();");
sb.AppendLine(" _context = _contextProvider.GetContext();");
sb.AppendLine(" _context ??= _contextProvider.GetContext();");
sb.AppendLine(" return _context;");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
sb.AppendLine(" }");
sb.AppendLine();
sb.AppendLine(" return _context;");
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine();
Expand All @@ -154,15 +164,21 @@ private static void GenerateContextProperty(StringBuilder sb)
sb.AppendLine(
" public static void SetContextProvider(global::GFramework.Core.Abstractions.Architectures.IArchitectureContextProvider provider)");
sb.AppendLine(" {");
sb.AppendLine(" _contextProvider = provider;");
sb.AppendLine(" lock (_contextSync)");
sb.AppendLine(" {");
sb.AppendLine(" _contextProvider = provider;");
sb.AppendLine(" }");
sb.AppendLine(" }");
sb.AppendLine();
sb.AppendLine(" /// <summary>");
sb.AppendLine(" /// 重置上下文提供者为默认值(用于测试清理)");
sb.AppendLine(" /// </summary>");
sb.AppendLine(" public static void ResetContextProvider()");
sb.AppendLine(" {");
sb.AppendLine(" _contextProvider = null;");
sb.AppendLine(" lock (_contextSync)");
sb.AppendLine(" {");
sb.AppendLine(" _contextProvider = null;");
sb.AppendLine(" }");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
sb.AppendLine(" }");
sb.AppendLine();
}
Expand Down
Loading
Loading