11using Microsoft . CodeAnalysis ;
22using Microsoft . CodeAnalysis . CSharp . Syntax ;
33using Microsoft . CodeAnalysis . Diagnostics ;
4- using System ;
54
65namespace WebApiClient . Analyzers
76{
@@ -10,16 +9,6 @@ namespace WebApiClient.Analyzers
109 /// </summary>
1110 class HttpApiContext
1211 {
13- /// <summary>
14- /// IHttpApi的类型
15- /// </summary>
16- private readonly Lazy < INamedTypeSymbol > ihttpApiType ;
17-
18- /// <summary>
19- /// AttributeCtorUsageAtribute的类型
20- /// </summary>
21- private readonly Lazy < INamedTypeSymbol > attributeCtorUsageAtributeType ;
22-
2312 /// <summary>
2413 /// IHttpApi的类型名称
2514 /// </summary>
@@ -33,35 +22,29 @@ class HttpApiContext
3322
3423
3524 /// <summary>
36- /// 获取IHttpApi的类型
25+ /// 获取语法节点上下文
3726 /// </summary>
38- public INamedTypeSymbol IHttpApiType
39- {
40- get => this . ihttpApiType . Value ;
41- }
27+ public SyntaxNodeAnalysisContext SyntaxNodeContext { get ; }
4228
4329 /// <summary>
44- /// 获取AttributeCtorUsageAtribute的类型
30+ /// 获取接口声明语法
4531 /// </summary>
46- public INamedTypeSymbol AttributeCtorUsageAtributeType
47- {
48- get => this . attributeCtorUsageAtributeType . Value ;
49- }
32+ public InterfaceDeclarationSyntax HttpApiSyntax { get ; }
5033
5134 /// <summary>
5235 /// 获取是否为HttpApi
5336 /// </summary>
5437 public bool IsHtttApi { get ; }
5538
5639 /// <summary>
57- /// 获取语法节点上下文
40+ /// 获取IHttpApi的类型
5841 /// </summary>
59- public SyntaxNodeAnalysisContext SyntaxNodeContext { get ; }
42+ public INamedTypeSymbol IHttpApiType { get ; }
6043
6144 /// <summary>
62- /// 获取接口声明语法
45+ /// 获取AttributeCtorUsageAtribute的类型
6346 /// </summary>
64- public InterfaceDeclarationSyntax HttpApiSyntax { get ; }
47+ public INamedTypeSymbol AttributeCtorUsageAtributeType { get ; }
6548
6649
6750 /// <summary>
@@ -73,18 +56,18 @@ public HttpApiContext(SyntaxNodeAnalysisContext syntaxNodeContext)
7356 this . SyntaxNodeContext = syntaxNodeContext ;
7457 this . HttpApiSyntax = syntaxNodeContext . Node as InterfaceDeclarationSyntax ;
7558
76- this . ihttpApiType = new Lazy < INamedTypeSymbol > ( ( ) => this . SyntaxNodeContext . Compilation . GetTypeByMetadataName ( ihttpApiTypeName ) , true ) ;
77- this . attributeCtorUsageAtributeType = new Lazy < INamedTypeSymbol > ( ( ) => this . SyntaxNodeContext . Compilation . GetTypeByMetadataName ( attributeCtorUsageTypName ) , true ) ;
59+ this . IHttpApiType = syntaxNodeContext . Compilation . GetTypeByMetadataName ( ihttpApiTypeName ) ;
60+ this . AttributeCtorUsageAtributeType = syntaxNodeContext . Compilation . GetTypeByMetadataName ( attributeCtorUsageTypName ) ;
7861
79- this . IsHtttApi = this . GetIsHtttApiInterface ( ) ;
62+ this . IsHtttApi = this . IsHtttApiInterface ( ) ;
8063 }
8164
8265
8366 /// <summary>
8467 /// 返回是否为HttpApi接口
8568 /// </summary>
8669 /// <returns></returns>
87- private bool GetIsHtttApiInterface ( )
70+ private bool IsHtttApiInterface ( )
8871 {
8972 if ( this . HttpApiSyntax == null || this . HttpApiSyntax . BaseList == null )
9073 {
@@ -103,4 +86,4 @@ private bool GetIsHtttApiInterface()
10386 return false ;
10487 }
10588 }
106- }
89+ }
0 commit comments