Skip to content

Commit a45c39f

Browse files
committed
Merge branch 'releases/7.x.x' into temp
2 parents d580de0 + d03e719 commit a45c39f

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/Thinktecture.Runtime.Extensions.SourceGenerator/CodeAnalysis/TypedMemberStateFactoryProvider.cs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ public class TypedMemberStateFactoryProvider
77
{
88
private static readonly object _lock7 = new();
99
private static readonly object _lock8 = new();
10+
private static readonly object _lock9 = new();
1011

1112
private static readonly Version _version7 = new(7, 0, 0, 0);
1213
private static readonly Version _version8 = new(8, 0, 0, 0);
14+
private static readonly Version _version9 = new(9, 0, 0, 0);
1315

1416
private static TypedMemberStateFactory? _dotnet7;
1517
private static TypedMemberStateFactory? _dotnet8;
18+
private static TypedMemberStateFactory? _dotnet9;
1619

1720
private static readonly ConcurrentDictionary<Version, TypedMemberStateFactory> _factoriesByVersion = new();
1821

@@ -31,40 +34,13 @@ public class TypedMemberStateFactoryProvider
3134
version = dotnetVersion;
3235

3336
if (version == _version7)
34-
{
35-
var factory = _dotnet7;
36-
37-
if (factory is not null)
38-
return factory;
39-
40-
lock (_lock7)
41-
{
42-
if (_dotnet7 is not null)
43-
return _dotnet7;
44-
45-
logger.LogDebug("Create TypedMemberStateFactory for .NET 7");
46-
47-
return _dotnet7 = TypedMemberStateFactory.Create(compilation);
48-
}
49-
}
37+
return GetFactory(compilation, logger, _version7, _lock7, ref _dotnet7);
5038

5139
if (version == _version8)
52-
{
53-
var factory = _dotnet8;
54-
55-
if (factory is not null)
56-
return factory;
57-
58-
lock (_lock8)
59-
{
60-
if (_dotnet8 is not null)
61-
return _dotnet8;
40+
return GetFactory(compilation, logger, _version8, _lock8, ref _dotnet8);
6241

63-
logger.LogDebug("Create TypedMemberStateFactory for .NET 8");
64-
65-
return _dotnet8 = TypedMemberStateFactory.Create(compilation);
66-
}
67-
}
42+
if (version == _version9)
43+
return GetFactory(compilation, logger, _version9, _lock9, ref _dotnet9);
6844

6945
if (version is null)
7046
{
@@ -80,4 +56,27 @@ public class TypedMemberStateFactoryProvider
8056
return TypedMemberStateFactory.Create(compilation);
8157
});
8258
}
59+
60+
private static TypedMemberStateFactory GetFactory(
61+
Compilation compilation,
62+
ILogger logger,
63+
Version dotnetVersion,
64+
object lockObj,
65+
ref TypedMemberStateFactory? cachedFactory)
66+
{
67+
var factory = cachedFactory;
68+
69+
if (factory is not null)
70+
return factory;
71+
72+
lock (lockObj)
73+
{
74+
if (cachedFactory is not null)
75+
return cachedFactory;
76+
77+
logger.LogDebug($"Create TypedMemberStateFactory for .NET {dotnetVersion}");
78+
79+
return cachedFactory = TypedMemberStateFactory.Create(compilation);
80+
}
81+
}
8382
}

0 commit comments

Comments
 (0)