@@ -12,32 +12,18 @@ namespace WebApiClientCore.Analyzers.SourceGenerator
1212 /// </summary>
1313 sealed class HttpApiProxyClass : IEquatable < HttpApiProxyClass >
1414 {
15- /// <summary>
16- /// 接口符号
17- /// </summary>
1815 private readonly INamedTypeSymbol httpApi ;
1916 private readonly string httpApiFullName ;
17+ private readonly string proxyClassName ;
2018
21- /// <summary>
22- /// 拦截器变量名
23- /// </summary>
24- private readonly string apiInterceptorFieldName = "_apiInterceptor" ;
25-
26- /// <summary>
27- /// action执行器变量名
28- /// </summary>
29- private readonly string actionInvokersFieldName = "_actionInvokers" ;
19+ private const string ApiInterceptorFieldName = "_apiInterceptor" ;
20+ private const string ActionInvokersFieldName = "_actionInvokers" ;
3021
3122 /// <summary>
3223 /// 文件名
3324 /// </summary>
3425 public string FileName { get ; }
3526
36- /// <summary>
37- /// 类型名
38- /// </summary>
39- public string ClassName { get ; }
40-
4127 /// <summary>
4228 /// HttpApi代理类
4329 /// </summary>
@@ -46,10 +32,8 @@ public HttpApiProxyClass(INamedTypeSymbol httpApi)
4632 {
4733 this . httpApi = httpApi ;
4834 this . httpApiFullName = GetFullName ( httpApi ) ;
49-
50- var httpApiName = httpApi . ToDisplayString ( ) ;
51- this . FileName = $ "{ nameof ( HttpApiProxyClass ) } .{ httpApiName } .g.cs";
52- this . ClassName = httpApiName . Replace ( "." , "_" ) ;
35+ this . proxyClassName = httpApi . ToDisplayString ( ) . Replace ( "." , "_" ) ;
36+ this . FileName = $ "{ nameof ( HttpApiProxyClass ) } .{ proxyClassName } .g.cs";
5337 }
5438
5539 /// <summary>
@@ -86,16 +70,16 @@ public override string ToString()
8670 builder . AppendLine ( "\t {" ) ;
8771 builder . AppendLine ( $ "\t \t [global::WebApiClientCore.HttpApiProxyClass(typeof({ this . httpApiFullName } ))]") ;
8872 builder . AppendLine ( $ "\t \t [global::System.Diagnostics.DebuggerTypeProxy(typeof({ this . httpApiFullName } ))]") ;
89- builder . AppendLine ( $ "\t \t sealed class { this . ClassName } : { this . httpApiFullName } ") ;
73+ builder . AppendLine ( $ "\t \t sealed class { this . proxyClassName } : { this . httpApiFullName } ") ;
9074 builder . AppendLine ( "\t \t {" ) ;
9175
92- builder . AppendLine ( $ "\t \t \t private readonly global::WebApiClientCore.IHttpApiInterceptor { this . apiInterceptorFieldName } ;") ;
93- builder . AppendLine ( $ "\t \t \t private readonly global::WebApiClientCore.ApiActionInvoker[] { this . actionInvokersFieldName } ;") ;
76+ builder . AppendLine ( $ "\t \t \t private readonly global::WebApiClientCore.IHttpApiInterceptor { ApiInterceptorFieldName } ;") ;
77+ builder . AppendLine ( $ "\t \t \t private readonly global::WebApiClientCore.ApiActionInvoker[] { ActionInvokersFieldName } ;") ;
9478 builder . AppendLine ( ) ;
95- builder . AppendLine ( $ "\t \t \t public { this . ClassName } (global::WebApiClientCore.IHttpApiInterceptor apiInterceptor, global::WebApiClientCore.ApiActionInvoker[] actionInvokers)") ;
79+ builder . AppendLine ( $ "\t \t \t public { this . proxyClassName } (global::WebApiClientCore.IHttpApiInterceptor apiInterceptor, global::WebApiClientCore.ApiActionInvoker[] actionInvokers)") ;
9680 builder . AppendLine ( "\t \t \t {" ) ;
97- builder . AppendLine ( $ "\t \t \t \t this.{ this . apiInterceptorFieldName } = apiInterceptor;") ;
98- builder . AppendLine ( $ "\t \t \t \t this.{ this . actionInvokersFieldName } = actionInvokers;") ;
81+ builder . AppendLine ( $ "\t \t \t \t this.{ ApiInterceptorFieldName } = apiInterceptor;") ;
82+ builder . AppendLine ( $ "\t \t \t \t this.{ ActionInvokersFieldName } = actionInvokers;") ;
9983 builder . AppendLine ( "\t \t \t }" ) ;
10084 builder . AppendLine ( ) ;
10185
@@ -138,7 +122,7 @@ private string BuildMethod(INamedTypeSymbol interfaceType, IMethodSymbol method,
138122 builder . AppendLine ( $ "\t \t \t [global::WebApiClientCore.HttpApiProxyMethod({ index } , \" { method . Name } \" , typeof({ GetFullName ( interfaceType ) } ))]") ;
139123 builder . AppendLine ( $ "\t \t \t { returnTypeString } { GetFullName ( interfaceType ) } .{ method . Name } ({ parametersString } )") ;
140124 builder . AppendLine ( "\t \t \t {" ) ;
141- builder . AppendLine ( $ "\t \t \t \t return ({ returnTypeString } )this.{ this . apiInterceptorFieldName } .Intercept(this.{ this . actionInvokersFieldName } [{ index } ], { parameterArrayString } );") ;
125+ builder . AppendLine ( $ "\t \t \t \t return ({ returnTypeString } )this.{ ApiInterceptorFieldName } .Intercept(this.{ ActionInvokersFieldName } [{ index } ], { parameterArrayString } );") ;
142126 builder . AppendLine ( "\t \t \t }" ) ;
143127 return builder . ToString ( ) ;
144128 }
0 commit comments