fix(codegen): Fixes codegen on VS2019 (#629)

- [X] Fixes code gen on VS2019
- [X] Fixes schema generator not iterating through all nodes
- [X] Fixes errors with building the actual code gen
This commit is contained in:
Kamron Batman 2021-05-31 16:30:17 -07:00 committed by GitHub
parent b6779a7c09
commit ac3958a0b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 198 additions and 45 deletions

View file

@ -16,6 +16,7 @@
using System;
using System.Collections.Immutable;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using SerializationGenerator;
@ -44,7 +45,8 @@ namespace SerializationSchemaGenerator
}
var projectFile = new FileInfo(project.FilePath!);
var migrationPath = Path.Join(projectFile.Directory?.FullName, "Migrations");
var projectPath = projectFile.Directory?.FullName;
var migrationPath = Path.Join(projectPath, "Migrations");
Directory.CreateDirectory(migrationPath);
var syntaxReceiver = new SerializerSyntaxReceiver();
@ -64,21 +66,32 @@ namespace SerializationSchemaGenerator
ReadCommentHandling = JsonCommentHandling.Skip
};
// var generatedSourcePath = Path.Join(projectPath, "Generated");
var serializableTypes = syntaxReceiver.SerializableList;
foreach (var (classSymbol, (attributeData, fieldsList)) in syntaxReceiver.ClassAndFields)
{
compilation.GenerateSchema(
var source = compilation.GenerateSerializationPartialClass(
classSymbol,
attributeData,
fieldsList.ToImmutableArray(),
migrationPath,
jsonOptions,
fieldsList.ToImmutableArray(),
serializableTypes
);
// WriteSource(generatedSourcePath, classSymbol.ToDisplayString(), source);
}
}
);
}
public static void WriteSource(string sourcePath, string className, string source)
{
Directory.CreateDirectory(sourcePath);
var filePath = Path.Combine(sourcePath, $"{className}.Serialization.cs");
File.WriteAllText(filePath, source, Encoding.UTF8);
}
}
}