mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-28 16:13:28 +08:00
- 移除ContextAwareServiceExtensions中GetService/GetSystem/GetModel/GetUtility方法的可空返回值 - 添加ContextGetGenerator源码生成器,支持通过特性自动生成上下文注入代码 - 新增GetService/GetServices/GetSystem/GetSystems/GetModel/GetModels/GetUtility/GetUtilities/GetAll特性 - 添加ContextGetDiagnostics提供注入相关的编译时诊断检查 - 实现INamedTypeSymbol扩展方法AreAllDeclarationsPartial用于检查partial类声明 - 添加ITypeSymbol扩展方法IsAssignableTo用于类型兼容性判断 - 创建FieldCandidateInfo和TypeCandidateInfo记录类型用于存储生成器候选信息 - 添加IsExternalInit内部类型支持低版本.NET框架的init-only setter功能 - 更新AnalyzerReleases.Unshipped.md添加新的诊断规则条目 - 创建完整的单元测试验证生成器功能和各种边界情况
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using Microsoft.CodeAnalysis;
|
|
|
|
namespace GFramework.SourceGenerators.Diagnostics;
|
|
|
|
/// <summary>
|
|
/// 提供 Context Get 注入生成器相关诊断。
|
|
/// </summary>
|
|
public static class ContextGetDiagnostics
|
|
{
|
|
/// <summary>
|
|
/// 不支持在嵌套类中生成注入代码。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor NestedClassNotSupported = new(
|
|
"GF_ContextGet_001",
|
|
"Context Get injection does not support nested classes",
|
|
"Class '{0}' cannot use context Get injection inside a nested type",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// 带注入语义的字段不能是静态字段。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor StaticFieldNotSupported = new(
|
|
"GF_ContextGet_002",
|
|
"Static field is not supported for context Get injection",
|
|
"Field '{0}' cannot be static when using generated context Get injection",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// 带注入语义的字段不能是只读字段。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor ReadOnlyFieldNotSupported = new(
|
|
"GF_ContextGet_003",
|
|
"Readonly field is not supported for context Get injection",
|
|
"Field '{0}' cannot be readonly when using generated context Get injection",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// 字段类型与注入特性不匹配。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor InvalidBindingType = new(
|
|
"GF_ContextGet_004",
|
|
"Field type is not valid for the selected context Get attribute",
|
|
"Field '{0}' type '{1}' is not valid for [{2}]",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// 使用 Context Get 注入的类型必须是上下文感知类型。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor ContextAwareTypeRequired = new(
|
|
"GF_ContextGet_005",
|
|
"Context-aware type is required",
|
|
"Class '{0}' must be context-aware to use generated context Get injection",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
|
|
/// <summary>
|
|
/// 一个字段不允许同时声明多个 Context Get 特性。
|
|
/// </summary>
|
|
public static readonly DiagnosticDescriptor MultipleBindingAttributesNotSupported = new(
|
|
"GF_ContextGet_006",
|
|
"Multiple context Get attributes are not supported on the same field",
|
|
"Field '{0}' cannot declare multiple generated context Get attributes",
|
|
"GFramework.SourceGenerators.Rule",
|
|
DiagnosticSeverity.Error,
|
|
true);
|
|
} |