From 8eaf83732732cab421c99f58d76a805d0a49a9ac Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Fri, 3 Apr 2026 23:50:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(analyzer):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E6=B3=A8=E5=86=8C=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=99=A8=E4=B8=AD=E7=9A=84=E8=AF=AD=E6=B3=95=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用属性模式匹配替换条件判断语句 - 简化了方法声明语法的空值检查逻辑 - 优化了构造函数声明语法的表达式体检查 - 提高了代码可读性和维护性 - 减少了冗余的语法树遍历操作 --- .../Analyzers/ContextRegistrationAnalyzer.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GFramework.SourceGenerators/Analyzers/ContextRegistrationAnalyzer.cs b/GFramework.SourceGenerators/Analyzers/ContextRegistrationAnalyzer.cs index 5d20f79e..c691fe65 100644 --- a/GFramework.SourceGenerators/Analyzers/ContextRegistrationAnalyzer.cs +++ b/GFramework.SourceGenerators/Analyzers/ContextRegistrationAnalyzer.cs @@ -818,13 +818,13 @@ public sealed class ContextRegistrationAnalyzer : DiagnosticAnalyzer var semanticModel = compilation.GetSemanticModel(syntax.SyntaxTree); var operation = syntax switch { - MethodDeclarationSyntax methodDeclaration when methodDeclaration.Body != null => + MethodDeclarationSyntax { Body: not null } methodDeclaration => semanticModel.GetOperation(methodDeclaration.Body), - MethodDeclarationSyntax methodDeclaration when methodDeclaration.ExpressionBody != null => + MethodDeclarationSyntax { ExpressionBody: not null } methodDeclaration => semanticModel.GetOperation(methodDeclaration.ExpressionBody.Expression), - ConstructorDeclarationSyntax constructorDeclaration when constructorDeclaration.Body != null => + ConstructorDeclarationSyntax { Body: not null } constructorDeclaration => semanticModel.GetOperation(constructorDeclaration.Body), - ConstructorDeclarationSyntax constructorDeclaration when constructorDeclaration.ExpressionBody != null => + ConstructorDeclarationSyntax { ExpressionBody: not null } constructorDeclaration => semanticModel.GetOperation(constructorDeclaration.ExpressionBody.Expression), _ => null };