mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
refactor(analyzer): 优化上下文注册分析器中的语法匹配逻辑
- 使用属性模式匹配替换条件判断语句 - 简化了方法声明语法的空值检查逻辑 - 优化了构造函数声明语法的表达式体检查 - 提高了代码可读性和维护性 - 减少了冗余的语法树遍历操作
This commit is contained in:
parent
c5a33ed571
commit
8eaf837327
@ -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
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user