about summary refs log tree commit diff
path: root/Utilities/LibMatrix.JsonSerializerContextGenerator/Program.cs
blob: 76d63572db6b750cff91f0dd7fee34dada45b4a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System.Reflection;
using ArcaneLibs;
using ArcaneLibs.Extensions.Streams;
using LibMatrix;
using LibMatrix.Interfaces;

// string binary = args.Length > 1 ? args[0] : Console.ReadLine()!;

// var asm = Assembly.LoadFrom(binary);
File.Delete("EventSerializerContexts.g.cs");
var stream = File.OpenWrite("EventSerializerContexts.g.cs");
var eventContentTypes = new ClassCollector<EventContent>().ResolveFromAllAccessibleAssemblies();
stream.WriteString(string.Join('\n', eventContentTypes//.DistinctBy(x => x.Namespace)
    .Select(x => $$"""
                  [System.Text.Json.Serialization.JsonSourceGenerationOptions(WriteIndented = true)]
                  [System.Text.Json.Serialization.JsonSerializable(typeof({{x.FullName}}))]
                  internal partial class {{x.Name}}SerializerContext : System.Text.Json.Serialization.JsonSerializerContext { }

                  """)));

await stream.FlushAsync();
stream.Close();