Skip to content

Commit 4fb19fb

Browse files
committed
增加Class后缀
1 parent 6b52ea4 commit 4fb19fb

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

WebApiClientCore.Analyzers/SourceGenerator/HttpApiProxyClass.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ sealed class HttpApiProxyClass : IEquatable<HttpApiProxyClass>
2121
/// <summary>
2222
/// 拦截器变量名
2323
/// </summary>
24-
private readonly string apiInterceptorFieldName = $"apiInterceptor_{(uint)Environment.TickCount}";
24+
private readonly string apiInterceptorFieldName = "_apiInterceptor";
2525

2626
/// <summary>
2727
/// action执行器变量名
2828
/// </summary>
29-
private readonly string actionInvokersFieldName = $"actionInvokers_{(uint)Environment.TickCount}";
29+
private readonly string actionInvokersFieldName = "_actionInvokers";
3030

3131
/// <summary>
3232
/// 文件名
@@ -41,7 +41,7 @@ sealed class HttpApiProxyClass : IEquatable<HttpApiProxyClass>
4141
/// <summary>
4242
/// 类型名
4343
/// </summary>
44-
public string ClassName => this.httpApi.Name;
44+
public string ClassName => this.httpApi.Name + "Class";
4545

4646
/// <summary>
4747
/// HttpApi代理类
@@ -89,13 +89,13 @@ public override string ToString()
8989
builder.AppendLine($"\t[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
9090
builder.AppendLine($"\t[global::System.Diagnostics.DebuggerTypeProxy(typeof({this.httpApiFullName}))]");
9191
builder.AppendLine($"\t[global::WebApiClientCore.HttpApiProxyClass(typeof({this.httpApiFullName}))]");
92-
builder.AppendLine($"\tpartial class {this.ClassName}:{this.httpApiFullName}");
92+
builder.AppendLine($"\tpartial class {this.ClassName} : {this.httpApiFullName}");
9393
builder.AppendLine("\t{");
9494

9595
builder.AppendLine($"\t\tprivate readonly global::WebApiClientCore.IHttpApiInterceptor {this.apiInterceptorFieldName};");
9696
builder.AppendLine($"\t\tprivate readonly global::WebApiClientCore.ApiActionInvoker[] {this.actionInvokersFieldName};");
9797

98-
builder.AppendLine($"\t\tpublic {this.httpApi.Name}(global::WebApiClientCore.IHttpApiInterceptor apiInterceptor, global::WebApiClientCore.ApiActionInvoker[] actionInvokers)");
98+
builder.AppendLine($"\t\tpublic {this.ClassName}(global::WebApiClientCore.IHttpApiInterceptor apiInterceptor, global::WebApiClientCore.ApiActionInvoker[] actionInvokers)");
9999
builder.AppendLine("\t\t{");
100100
builder.AppendLine($"\t\t\tthis.{this.apiInterceptorFieldName} = apiInterceptor;");
101101
builder.AppendLine($"\t\t\tthis.{this.actionInvokersFieldName} = actionInvokers;");
@@ -138,7 +138,7 @@ private string BuildMethod(INamedTypeSymbol interfaceType, IMethodSymbol method,
138138
: $"new global::System.Object[] {{ {parameterNamesString} }}";
139139

140140
var methodName = $"\"{interfaceType.ToDisplayString()}.{method.Name}\"";
141-
var returnTypeString = GetFullName(method.ReturnType);
141+
var returnTypeString = GetFullName(method.ReturnType);
142142
builder.AppendLine($"\t\t[global::WebApiClientCore.HttpApiProxyMethod({index}, {methodName})]");
143143
builder.AppendLine($"\t\t{returnTypeString} {GetFullName(interfaceType)}.{method.Name}( {parametersString} )");
144144
builder.AppendLine("\t\t{");

WebApiClientCore.Analyzers/SourceGenerator/HttpApiProxyClassInitializer.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,30 @@ public SourceText ToSourceText()
3939
return SourceText.From(code, Encoding.UTF8);
4040
}
4141

42+
4243
public override string ToString()
4344
{
4445
var builder = new StringBuilder();
4546
builder.AppendLine("#if NET5_0_OR_GREATER");
46-
builder.AppendLine("#pragma warning disable");
47+
builder.AppendLine("#pragma warning disable");
4748
builder.AppendLine($"namespace WebApiClientCore");
4849
builder.AppendLine("{");
49-
builder.AppendLine(" /// <summary>动态依赖初始化器</summary>");
50-
builder.AppendLine(" [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
51-
builder.AppendLine($" static partial class {nameof(HttpApiProxyClassInitializer)}");
52-
builder.AppendLine(" {");
53-
54-
builder.AppendLine($"""
55-
/// <summary>
56-
/// 注册程序集{compilation.AssemblyName}的所有动态依赖
57-
/// 避免程序集在裁剪时裁剪掉由SourceGenerator生成的代理类
58-
/// </summary>
59-
""");
50+
builder.AppendLine("\t/// <summary>动态依赖初始化器</summary>");
51+
builder.AppendLine("\t[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]");
52+
builder.AppendLine($"\tstatic partial class {nameof(HttpApiProxyClassInitializer)}");
53+
builder.AppendLine("\t{");
6054

61-
builder.AppendLine(" [global::System.Runtime.CompilerServices.ModuleInitializer]");
55+
builder.AppendLine($"\t\t/// <summary>初始化本程序集的动态依赖</summary> ");
56+
builder.AppendLine("\t\t[global::System.Runtime.CompilerServices.ModuleInitializer]");
6257
foreach (var item in this.proxyClasses)
6358
{
64-
builder.AppendLine($" [global::System.Diagnostics.CodeAnalysis.DynamicDependency(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::{item.Namespace}.{item.ClassName}))]");
59+
builder.AppendLine($"\t\t[global::System.Diagnostics.CodeAnalysis.DynamicDependency(global::System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All, typeof(global::{item.Namespace}.{item.ClassName}))]");
6560
}
6661

67-
builder.AppendLine(" public static void Initialize()");
68-
builder.AppendLine(" {");
69-
builder.AppendLine(" }");
70-
builder.AppendLine(" }");
62+
builder.AppendLine("\t\tpublic static void Initialize()");
63+
builder.AppendLine("\t\t{");
64+
builder.AppendLine("\t\t}");
65+
builder.AppendLine("\t}");
7166
builder.AppendLine("}");
7267
builder.AppendLine("#pragma warning restore");
7368
builder.AppendLine("#endif");

0 commit comments

Comments
 (0)