2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-06-13 14:38:43 +00:00

TypeDefGenerator

This commit is contained in:
2026-06-08 23:25:49 +03:00
parent 0939f71464
commit 2bdd5d5022
23 changed files with 348 additions and 43 deletions
+20 -5
View File
@@ -271,9 +271,13 @@ public static class TypeDefGenerator
// generate info class
var mainClassName = typeDefs.FirstOrDefault().Name?.Split('.');
var mainNamespace = mainClassName != null ? string.Join(".", mainClassName.Take(mainClassName.Length - 1)) : "Esiur";
var typesFile = @"using System;
namespace Esiur {
public static class Generated {
namespace " + mainNamespace + @" {
public static class Initialization {
public static Type[] Resources {get;} = new Type[] { " +
string.Join(",", typeDefs.Where(x => x.Kind == TypeDefKind.Resource).Select(x => $"typeof({x.Name})"))
+ @" };
@@ -282,11 +286,22 @@ public static class TypeDefGenerator
+ @" };
public static Type[] Enums { get; } = new Type[] { " +
string.Join(",", typeDefs.Where(x => x.Kind == TypeDefKind.Enum).Select(x => $"typeof({x.Name})"))
+ @" };" +
"\r\n } \r\n}";
+ @" };
public static void RegisterTypes(Warehouse warehouse)
{
foreach(var type in Resources)
warehouse.RegisterProxyType(type);
foreach(var type in Records)
warehouse.RegisterProxyType(type);
foreach(var type in Enums)
warehouse.RegisterProxyType(type);
}
\r\n } \r\n}";
File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + "Esiur.g.cs", typesFile);
File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + "Initialization.g.cs", typesFile);
return dstDir.FullName;