mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 实现了 LoggerGenerator 源代码生成器,为标记 LogAttribute 的类自动生成日志字段 - 添加了 LogAttribute 特性,支持配置日志分类、字段名、访问修饰符和静态属性 - 创建了 Diagnostics 静态类,定义 GFLOG001 诊断规则检查 partial 类声明 - 集成 Microsoft.CodeAnalysis 包,启用增量生成器和扩展分析器规则 - 生成的代码包含命名空间、类名和日志字段的完整实现
26 lines
858 B
C#
26 lines
858 B
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
|
||
);
|
||
}
|