перевод на передачу с обозначением схемы

This commit is contained in:
2025-02-12 12:34:54 +03:00
parent 318484025d
commit 5032fa28e8
18 changed files with 143 additions and 62 deletions
+8 -8
View File
@@ -77,14 +77,15 @@ namespace {Namespace}
/// </summary>
/// <param name="context">Source generation context used to add source files.</param>
/// <param name="compilation">Compilation used to provide access to the Semantic Model.</param>
/// <param name="classDeclarations">Nodes annotated with the [Report] attribute that trigger the generate action.</param>
/// <param name="classes">Nodes annotated with the [Report] attribute that trigger the generate action.</param>
private void GenerateCode(SourceProductionContext context, Compilation compilation,
ImmutableArray<InterfaceDeclarationSyntax> classDeclarations)
ImmutableArray<InterfaceDeclarationSyntax> classes)
{
var methods = new List<(string, IMethodSymbol)>();
var frontendContextRepo = new List<string>();
// Go through all filtered class declarations.
foreach (var classDeclarationSyntax in classDeclarations)
var declarations = classes.ToList().OrderBy(i => i.Identifier.Text).ToList();
foreach (var classDeclarationSyntax in declarations)
{
// We need to get semantic model of the class to retrieve metadata.
var semanticModel = compilation.GetSemanticModel(classDeclarationSyntax.SyntaxTree);
@@ -102,7 +103,7 @@ namespace {Namespace}
// Go through all class members with a particular type (property) to generate method lines.
var methodBody = classSymbol.GetMembers()
.OfType<IMethodSymbol>();
.OfType<IMethodSymbol>().OrderBy(i => i.Name);
var originalName = className;
// Build up the source code
@@ -204,7 +205,7 @@ partial class {className} (int id, ISerialisationModule.IFrontendSerialisationMo
var methodsStringed = methods.Select(i =>
$"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", [{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}])")
.ToList();
var coCodegenRepoCode = @$"// <auto-generated/>
using System.Collections.Generic;
using System.Reflection;
@@ -212,10 +213,10 @@ using mROA.Abstract;
namespace mROA.Codegen;
public class CoCodegenMethodRepository :IMethodRepository
public class CoCodegenMethodRepository : IMethodRepository
{{
private readonly List<MethodInfo> _methods = [
{string.Join(", \r\n\t\t", methodsStringed)}
{string.Join(", // test comment\r\n\t\t", methodsStringed)}
];
public MethodInfo GetMethod(int id)
{{
@@ -310,6 +311,5 @@ public class FrontendContextRepository : IContextRepository
";
context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
}
}
}