11using System ;
2- using System . Collections . Concurrent ;
32using System . Collections . Generic ;
43using System . Reflection ;
54
@@ -12,7 +11,7 @@ static class SourceGeneratorProxyClassType
1211 {
1312 private static readonly object syncRoot = new ( ) ;
1413 private static readonly HashSet < Assembly > assemblies = [ ] ;
15- private static readonly ConcurrentDictionary < Type , Type > httpApiProxyClassTable = [ ] ;
14+ private static readonly Dictionary < Type , Type > httpApiProxyClassTable = [ ] ;
1615 private const string HttpApiProxyClassTypeName = "WebApiClientCore.HttpApiProxyClass" ;
1716
1817 /// <summary>
@@ -22,7 +21,13 @@ static class SourceGeneratorProxyClassType
2221 /// <returns></returns>
2322 public static Type ? Find ( Type httpApiType )
2423 {
25- AnalyzeAssembly ( httpApiType . Assembly ) ;
24+ lock ( syncRoot )
25+ {
26+ if ( assemblies . Add ( httpApiType . Assembly ) )
27+ {
28+ AnalyzeAssembly ( httpApiType . Assembly ) ;
29+ }
30+ }
2631
2732 if ( httpApiProxyClassTable . TryGetValue ( httpApiType , out var proxyClassType ) )
2833 {
@@ -34,32 +39,18 @@ static class SourceGeneratorProxyClassType
3439
3540 private static void AnalyzeAssembly ( Assembly assembly )
3641 {
37- if ( AddAssembly ( assembly ) )
42+ var httpApiProxyClass = assembly . GetType ( HttpApiProxyClassTypeName ) ;
43+ if ( httpApiProxyClass != null )
3844 {
39- var httpApiProxyClass = assembly . GetType ( HttpApiProxyClassTypeName ) ;
40- if ( httpApiProxyClass != null )
45+ foreach ( var classType in httpApiProxyClass . GetNestedTypes ( BindingFlags . NonPublic ) )
4146 {
42- foreach ( var classType in httpApiProxyClass . GetNestedTypes ( BindingFlags . NonPublic ) )
47+ var proxyClassAttr = classType . GetCustomAttribute < HttpApiProxyClassAttribute > ( ) ;
48+ if ( proxyClassAttr != null && proxyClassAttr . HttpApiType . IsAssignableFrom ( classType ) )
4349 {
44- if ( classType . IsClass )
45- {
46- var proxyClassAttr = classType . GetCustomAttribute < HttpApiProxyClassAttribute > ( ) ;
47- if ( proxyClassAttr != null && proxyClassAttr . HttpApiType . IsAssignableFrom ( classType ) )
48- {
49- httpApiProxyClassTable . TryAdd ( proxyClassAttr . HttpApiType , classType ) ;
50- }
51- }
50+ httpApiProxyClassTable . TryAdd ( proxyClassAttr . HttpApiType , classType ) ;
5251 }
5352 }
5453 }
5554 }
56-
57- private static bool AddAssembly ( Assembly assembly )
58- {
59- lock ( syncRoot )
60- {
61- return assemblies . Add ( assembly ) ;
62- }
63- }
6455 }
6556}
0 commit comments