mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 11:14:30 +08:00
- 定义新的诊断描述符GFW_LOG001用于检测LogAttribute无法生成Logger的情况 - 在代码生成过程中验证LogAttribute是否存在及构造参数有效性 - 当LogAttribute缺失或参数无效时报告诊断错误并提供详细信息 - 修复代码格式化问题并优化代码生成逻辑 - 更新AnalyzerReleases.Unshipped.md文档添加新诊断规则 - 改进Generate方法参数传递和错误处理机制
40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using Microsoft.CodeAnalysis;
|
||
|
||
namespace GFramework.Generator.generator.logging;
|
||
|
||
/// <summary>
|
||
/// 提供诊断描述符的静态类,用于GFramework日志生成器的编译时检查
|
||
/// </summary>
|
||
internal static class Diagnostics
|
||
{
|
||
|
||
/// <summary>
|
||
/// 定义诊断描述符:要求使用[Log]特性的类必须声明为partial
|
||
/// </summary>
|
||
/// <remarks>
|
||
/// 当类使用[Log]特性但未声明为partial时,编译器将报告此错误
|
||
/// </remarks>
|
||
public static readonly DiagnosticDescriptor MustBePartial =
|
||
new(
|
||
id: "GFLOG001",
|
||
title: "Class must be partial",
|
||
messageFormat: "Class '{0}' must be declared partial to use [Log]",
|
||
category: "GFramework.Logging",
|
||
DiagnosticSeverity.Error,
|
||
isEnabledByDefault: true
|
||
);
|
||
|
||
/// <summary>
|
||
/// 定义诊断描述符:LogAttribute无法生成Logger的错误情况
|
||
/// </summary>
|
||
public static readonly DiagnosticDescriptor LogAttributeInvalid =
|
||
new(
|
||
id: "GFW_LOG001",
|
||
title: "LogAttribute 无法生成 Logger",
|
||
messageFormat: "类 '{0}' 上的 LogAttribute 无法生效:{1}",
|
||
category: "GFramework.Logging",
|
||
DiagnosticSeverity.Warning,
|
||
isEnabledByDefault: true);
|
||
|
||
}
|