mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
test(registration): 添加自动注册导出集合生成器测试
- 添加了批量注册方法生成的基础功能测试 - 添加了集合元素类型推断失败时的诊断报告测试 - 添加了数组参数注册方法的生成测试 - 添加了从继承接口获取注册方法的测试 - 添加了显式接口实现成员不可访问的诊断测试 - 添加了从基类获取注册方法的测试 - 添加了从基类获取注册器成员的测试 - 添加了非实例可读集合成员的诊断测试 - 添加了非实例可读注册器成员的诊断测试 - 添加了注册方法不可访问的诊断测试 - 添加了属性参数无效时的诊断测试 - 添加了多个分部声明时只生成一个源文件的测试
This commit is contained in:
parent
56bc078288
commit
973a3c3cb4
@ -327,8 +327,7 @@ public class AutoRegisterExportedCollectionsGeneratorTests
|
||||
{
|
||||
Sources = { source }
|
||||
},
|
||||
DisabledDiagnostics = { "GF_Common_Trace_001" },
|
||||
TestBehaviors = TestBehaviors.SkipGeneratedSourcesCheck
|
||||
DisabledDiagnostics = { "GF_Common_Trace_001" }
|
||||
};
|
||||
|
||||
test.ExpectedDiagnostics.Add(new DiagnosticResult("GF_AutoExport_003", DiagnosticSeverity.Error)
|
||||
|
||||
@ -357,15 +357,23 @@ public sealed class AutoRegisterExportedCollectionsGenerator : IIncrementalGener
|
||||
INamedTypeSymbol registryType,
|
||||
string registerMethodName)
|
||||
{
|
||||
// Start from the declared registry type so directly declared overloads win the cheap checks
|
||||
// before we expand into inherited declarations.
|
||||
foreach (var method in registryType.GetMembers(registerMethodName).OfType<IMethodSymbol>())
|
||||
yield return method;
|
||||
|
||||
// Concrete registry types can inherit callable implementations from base classes. When the
|
||||
// registry itself is an interface, BaseType is null and this phase intentionally yields nothing.
|
||||
for (var baseType = registryType.BaseType; baseType is not null; baseType = baseType.BaseType)
|
||||
{
|
||||
foreach (var method in baseType.GetMembers(registerMethodName).OfType<IMethodSymbol>())
|
||||
yield return method;
|
||||
}
|
||||
|
||||
// Only interface-typed registry members should search interface inheritance. For classes or
|
||||
// structs this avoids accepting explicit interface implementations that generated code cannot
|
||||
// call through `this.<registry>.<method>(...)`. AllInterfaces is already transitive, so the
|
||||
// same semantic contract may appear multiple times; that is safe because the caller only uses Any().
|
||||
if (registryType.TypeKind != TypeKind.Interface)
|
||||
yield break;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user