1
1
using System ;
2
- using System . Collections . Concurrent ;
3
2
using System . Collections . Generic ;
4
3
using System . Reflection ;
5
4
@@ -12,7 +11,7 @@ static class SourceGeneratorProxyClassType
12
11
{
13
12
private static readonly object syncRoot = new ( ) ;
14
13
private static readonly HashSet < Assembly > assemblies = [ ] ;
15
- private static readonly ConcurrentDictionary < Type , Type > httpApiProxyClassTable = [ ] ;
14
+ private static readonly Dictionary < Type , Type > httpApiProxyClassTable = [ ] ;
16
15
private const string HttpApiProxyClassTypeName = "WebApiClientCore.HttpApiProxyClass" ;
17
16
18
17
/// <summary>
@@ -22,7 +21,13 @@ static class SourceGeneratorProxyClassType
22
21
/// <returns></returns>
23
22
public static Type ? Find ( Type httpApiType )
24
23
{
25
- AnalyzeAssembly ( httpApiType . Assembly ) ;
24
+ lock ( syncRoot )
25
+ {
26
+ if ( assemblies . Add ( httpApiType . Assembly ) )
27
+ {
28
+ AnalyzeAssembly ( httpApiType . Assembly ) ;
29
+ }
30
+ }
26
31
27
32
if ( httpApiProxyClassTable . TryGetValue ( httpApiType , out var proxyClassType ) )
28
33
{
@@ -34,32 +39,18 @@ static class SourceGeneratorProxyClassType
34
39
35
40
private static void AnalyzeAssembly ( Assembly assembly )
36
41
{
37
- if ( AddAssembly ( assembly ) )
42
+ var httpApiProxyClass = assembly . GetType ( HttpApiProxyClassTypeName ) ;
43
+ if ( httpApiProxyClass != null )
38
44
{
39
- var httpApiProxyClass = assembly . GetType ( HttpApiProxyClassTypeName ) ;
40
- if ( httpApiProxyClass != null )
45
+ foreach ( var classType in httpApiProxyClass . GetNestedTypes ( BindingFlags . NonPublic ) )
41
46
{
42
- foreach ( var classType in httpApiProxyClass . GetNestedTypes ( BindingFlags . NonPublic ) )
47
+ var proxyClassAttr = classType . GetCustomAttribute < HttpApiProxyClassAttribute > ( ) ;
48
+ if ( proxyClassAttr != null && proxyClassAttr . HttpApiType . IsAssignableFrom ( classType ) )
43
49
{
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 ) ;
52
51
}
53
52
}
54
53
}
55
54
}
56
-
57
- private static bool AddAssembly ( Assembly assembly )
58
- {
59
- lock ( syncRoot )
60
- {
61
- return assemblies . Add ( assembly ) ;
62
- }
63
- }
64
55
}
65
56
}
0 commit comments