Skip to content

Commit 9383e26

Browse files
committed
Moving static schema objects to local
We can't share the value because the data is different between projects. It does mean each target framework will re-process the data though that isn't a huge issue.
1 parent 0d08df2 commit 9383e26

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

Tools/Schema.NET.Tool/SchemaSourceGenerator.cs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,11 @@ namespace Schema.NET.Tool
1313
[Generator]
1414
public class SchemaSourceGenerator : ISourceGenerator
1515
{
16-
private static readonly object SchemaLock = new();
17-
18-
private static IEnumerable<GeneratorSchemaObject>? SchemaObjects { get; set; }
19-
2016
public void Initialize(GeneratorInitializationContext context)
2117
{
2218
}
2319

2420
public void Execute(GeneratorExecutionContext context)
25-
{
26-
// Initialization with configuration is only possible with the GeneratorExecutionContext
27-
InitializeWithConfig(context);
28-
29-
if (SchemaObjects is not null)
30-
{
31-
foreach (var schemaObject in SchemaObjects)
32-
{
33-
var source = string.Empty;
34-
if (schemaObject is GeneratorSchemaClass schemaClass)
35-
{
36-
source = RenderClass(schemaClass);
37-
}
38-
else if (schemaObject is GeneratorSchemaEnumeration schemaEnumeration)
39-
{
40-
source = RenderEnumeration(schemaEnumeration);
41-
}
42-
43-
context.AddSource($"{schemaObject.Layer}.{schemaObject.Name}.Generated.cs", source);
44-
}
45-
}
46-
}
47-
48-
private static void InitializeWithConfig(GeneratorExecutionContext context)
4921
{
5022
var schemaDataStream = Assembly
5123
.GetExecutingAssembly()
@@ -64,16 +36,25 @@ private static void InitializeWithConfig(GeneratorExecutionContext context)
6436
schemaRepository,
6537
IncludePendingSchemaObjects(context));
6638

67-
if (SchemaObjects is null)
39+
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
40+
var schemaObjects = schemaService.GetObjectsAsync().GetAwaiter().GetResult();
41+
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
42+
43+
if (schemaObjects is not null)
6844
{
69-
lock (SchemaLock)
45+
foreach (var schemaObject in schemaObjects)
7046
{
71-
if (SchemaObjects is null)
47+
var source = string.Empty;
48+
if (schemaObject is GeneratorSchemaClass schemaClass)
7249
{
73-
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
74-
SchemaObjects = schemaService.GetObjectsAsync().GetAwaiter().GetResult();
75-
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
50+
source = RenderClass(schemaClass);
51+
}
52+
else if (schemaObject is GeneratorSchemaEnumeration schemaEnumeration)
53+
{
54+
source = RenderEnumeration(schemaEnumeration);
7655
}
56+
57+
context.AddSource($"{schemaObject.Layer}.{schemaObject.Name}.Generated.cs", source);
7758
}
7859
}
7960
}

0 commit comments

Comments
 (0)