chore: add documentation comments and stylecop rules

This commit is contained in:
2025-12-04 11:25:01 +08:00
parent 17d143a351
commit 8e4c2b0e45
142 changed files with 1309 additions and 439 deletions

View File

@@ -6,7 +6,7 @@ namespace TakeoutSaaS.Shared.Abstractions.Results;
/// <summary>
/// 统一的 API 返回结果包装。
/// </summary>
/// <typeparam name="T">数据载荷类型</typeparam>
/// <typeparam name="T">数据载荷类型</typeparam>
public sealed record ApiResponse<T>
{
/// <summary>
@@ -92,6 +92,9 @@ public sealed record ApiResponse<T>
Timestamp = DateTime.UtcNow
};
/// <summary>
/// 解析当前 TraceId。
/// </summary>
private static string ResolveTraceId()
{
if (!string.IsNullOrWhiteSpace(TraceContext.TraceId))
@@ -113,9 +116,19 @@ public sealed record ApiResponse<T>
}
}
/// <summary>
/// 作为 TraceId 缺失时的本地雪花 ID 备用生成器。
/// </summary>
internal sealed class IdFallbackGenerator
{
/// <summary>
/// 延迟初始化的单例实例承载。
/// </summary>
private static readonly Lazy<IdFallbackGenerator> Lazy = new(() => new IdFallbackGenerator());
/// <summary>
/// 获取备用雪花生成器单例。
/// </summary>
public static IdFallbackGenerator Instance => Lazy.Value;
private readonly object _sync = new();
@@ -126,6 +139,9 @@ internal sealed class IdFallbackGenerator
{
}
/// <summary>
/// 生成雪花风格的本地备用 ID。
/// </summary>
public long NextId()
{
lock (_sync)
@@ -149,6 +165,9 @@ internal sealed class IdFallbackGenerator
}
}
/// <summary>
/// 等待到下一个毫秒以避免序列冲突。
/// </summary>
private static long WaitNextMillis(long lastTimestamp)
{
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();