@@ -103,41 +103,32 @@ public override string ToString()
103103 builder . AppendLine ( ) ;
104104
105105 var index = 0 ;
106- foreach ( var method in this . FindApiMethods ( ) )
106+ foreach ( var interfaceType in this . httpApi . AllInterfaces . Append ( httpApi ) )
107107 {
108- var methodCode = this . BuildMethod ( method , index ) ;
109- builder . AppendLine ( methodCode ) ;
110- index += 1 ;
108+ foreach ( var method in interfaceType . GetMembers ( ) . OfType < IMethodSymbol > ( ) )
109+ {
110+ var methodCode = this . BuildMethod ( interfaceType , method , index ) ;
111+ builder . AppendLine ( methodCode ) ;
112+ index += 1 ;
113+ }
111114 }
112115
116+
113117 builder . AppendLine ( "\t }" ) ;
114118 builder . AppendLine ( "}" ) ;
115119 builder . AppendLine ( "#pragma warning restore" ) ;
116120
117121 return builder . ToString ( ) ;
118122 }
119123
120- /// <summary>
121- /// 查找接口类型及其继承的接口的所有方法
122- /// </summary>
123- /// <returns></returns>
124- private IEnumerable < IMethodSymbol > FindApiMethods ( )
125- {
126- #pragma warning disable RS1024
127- return this . httpApi . AllInterfaces . Append ( httpApi )
128- . SelectMany ( item => item . GetMembers ( ) )
129- . OfType < IMethodSymbol > ( )
130- . Distinct ( MethodEqualityComparer . Default ) ;
131- #pragma warning restore RS1024
132- }
133-
134124 /// <summary>
135125 /// 构建方法
136126 /// </summary>
127+ /// <param name="interfaceType"></param>
137128 /// <param name="method"></param>
138129 /// <param name="index"></param>
139130 /// <returns></returns>
140- private string BuildMethod ( IMethodSymbol method , int index )
131+ private string BuildMethod ( INamedTypeSymbol interfaceType , IMethodSymbol method , int index )
141132 {
142133 var builder = new StringBuilder ( ) ;
143134 var parametersString = string . Join ( "," , method . Parameters . Select ( item => $ "{ GetFullName ( item . Type ) } { item . Name } ") ) ;
@@ -146,9 +137,10 @@ private string BuildMethod(IMethodSymbol method, int index)
146137 ? "global::System.Array.Empty<global::System.Object>()"
147138 : $ "new global::System.Object[] {{ { parameterNamesString } }}";
148139
140+ var methodName = $ "\" { interfaceType . ToDisplayString ( ) } .{ method . Name } \" ";
149141 var returnTypeString = GetFullName ( method . ReturnType ) ;
150- builder . AppendLine ( $ "\t \t [global::WebApiClientCore.HttpApiProxyMethod({ index } )]") ;
151- builder . AppendLine ( $ "\t \t public { returnTypeString } { method . Name } ( { parametersString } )") ;
142+ builder . AppendLine ( $ "\t \t [global::WebApiClientCore.HttpApiProxyMethod({ index } , { methodName } )]") ;
143+ builder . AppendLine ( $ "\t \t { returnTypeString } { GetFullName ( interfaceType ) } . { method . Name } ( { parametersString } )") ;
152144 builder . AppendLine ( "\t \t {" ) ;
153145 builder . AppendLine ( $ "\t \t \t return ({ returnTypeString } )this.{ this . apiInterceptorFieldName } .Intercept(this.{ this . actionInvokersFieldName } [{ index } ], { paremterArrayString } );") ;
154146 builder . AppendLine ( "\t \t }" ) ;
0 commit comments