кодген фронтенд репозитория реализован

This commit is contained in:
2025-02-05 00:26:28 +03:00
parent f3ece97ebf
commit cf87d6b98e
5 changed files with 59 additions and 8 deletions
@@ -84,7 +84,7 @@ namespace {Namespace}
ImmutableArray<InterfaceDeclarationSyntax> classDeclarations)
{
var methods = new List<(string, IMethodSymbol)>();
var frontendContextRepo = new List<string>();
// Go through all filtered class declarations.
foreach (var classDeclarationSyntax in classDeclarations)
{
@@ -96,6 +96,7 @@ namespace {Namespace}
if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol)
continue;
var namespaceName = classSymbol.ContainingNamespace.ToDisplayString();
// 'Identifier' means the token of the node. Get class name from the syntax node.
@@ -191,6 +192,8 @@ partial class {className} (int id, ISerialisationModule.IFrontendSerialisationMo
// Add the source code to the compilation.
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
frontendContextRepo.Add($"{{ typeof({classSymbol.ToDisplayString()}), typeof({namespaceName}.{className}) }}");
}
@@ -230,5 +233,57 @@ public class CoCodegenMethodRepository :IMethodRepository
}}
";
context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
var fronendRepoCode = @$"// <auto-generated/>
using System.Collections.Frozen;
namespace mROA.Implementation;
public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository
{{
private static readonly FrozenDictionary<Type, Type> _remoteTypes = new Dictionary<Type, Type> {{
{string.Join(", \r\n\t\t", frontendContextRepo)}}}.ToFrozenDictionary();
public int ResisterObject(object o)
{{
throw new NotSupportedException();
}}
public void ClearObject(int id)
{{
throw new NotSupportedException();
}}
public object GetObject(int id)
{{
throw new NotSupportedException();
}}
public T GetObject<T>(int id)
{{
if (_remoteTypes.TryGetValue(typeof(T), out var remoteType))
{{
var remote = (T)Activator.CreateInstance(remoteType, id, serialisationModule)!;
return remote;
}}
throw new NotSupportedException();
}}
public object GetSingleObject(Type type)
{{
return Activator.CreateInstance(_remoteTypes[type], -1, serialisationModule)!;
}}
public int GetObjectIndex(object o)
{{
if (o is IRemoteObject remote)
{{
return remote.Id;
}}
throw new NotSupportedException();
}}
}}
";
context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
}
}
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2fac34a1ceac82d71c748b1421917d8fc2a60fa7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f3ece97ebf7746e8d4439601aab0ec75815f30cf")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Codegen")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2fac34a1ceac82d71c748b1421917d8fc2a60fa7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f3ece97ebf7746e8d4439601aab0ec75815f30cf")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA.Example")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
-4
View File
@@ -35,10 +35,6 @@ public class FrontendFinalTest
_frontendInteractionModule = new StreamBasedFrontendInteractionModule();
_frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule);
_frontendContextRepository = new FrontendContextRepository(new Dictionary<Type, Type> {
{ typeof(ITestController), typeof(TestControllerRemoteEndpoint) },
{typeof(ITestParameter), typeof(TestParameterRemoteEndpoint)}
}, _frontendSerialisationModule);
Task.Run(() =>
{
+1 -1
View File
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("mROA")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2fac34a1ceac82d71c748b1421917d8fc2a60fa7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f3ece97ebf7746e8d4439601aab0ec75815f30cf")]
[assembly: System.Reflection.AssemblyProductAttribute("mROA")]
[assembly: System.Reflection.AssemblyTitleAttribute("mROA")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]