diff --git a/mROA.Codegen/SampleIncrementalSourceGenerator.cs b/mROA.Codegen/SampleIncrementalSourceGenerator.cs index 63f11a5..00ade68 100644 --- a/mROA.Codegen/SampleIncrementalSourceGenerator.cs +++ b/mROA.Codegen/SampleIncrementalSourceGenerator.cs @@ -84,7 +84,7 @@ namespace {Namespace} ImmutableArray classDeclarations) { var methods = new List<(string, IMethodSymbol)>(); - + var frontendContextRepo = new List(); // 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 = @$"// +using System.Collections.Frozen; + +namespace mROA.Implementation; + +public class FrontendContextRepository(ISerialisationModule.IFrontendSerialisationModule serialisationModule) : IContextRepository +{{ + private static readonly FrozenDictionary _remoteTypes = new Dictionary {{ + {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(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)); } } \ No newline at end of file diff --git a/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs b/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs index 4762005..09ecb14 100644 --- a/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs +++ b/mROA.Codegen/obj/Debug/netstandard2.0/mROA.Codegen.AssemblyInfo.cs @@ -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")] diff --git a/mROA.Example/obj/Debug/net9.0/mROA.Example.AssemblyInfo.cs b/mROA.Example/obj/Debug/net9.0/mROA.Example.AssemblyInfo.cs index daf7e8e..c9f1179 100644 --- a/mROA.Example/obj/Debug/net9.0/mROA.Example.AssemblyInfo.cs +++ b/mROA.Example/obj/Debug/net9.0/mROA.Example.AssemblyInfo.cs @@ -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")] diff --git a/mROA.Test/FrontendFinalTest.cs b/mROA.Test/FrontendFinalTest.cs index 6538040..94db938 100644 --- a/mROA.Test/FrontendFinalTest.cs +++ b/mROA.Test/FrontendFinalTest.cs @@ -35,10 +35,6 @@ public class FrontendFinalTest _frontendInteractionModule = new StreamBasedFrontendInteractionModule(); _frontendSerialisationModule = new JsonFrontendSerialisationModule(_frontendInteractionModule); - _frontendContextRepository = new FrontendContextRepository(new Dictionary { - { typeof(ITestController), typeof(TestControllerRemoteEndpoint) }, - {typeof(ITestParameter), typeof(TestParameterRemoteEndpoint)} - }, _frontendSerialisationModule); Task.Run(() => { diff --git a/mROA/obj/Debug/net9.0/mROA.AssemblyInfo.cs b/mROA/obj/Debug/net9.0/mROA.AssemblyInfo.cs index c2dc808..c84871c 100644 --- a/mROA/obj/Debug/net9.0/mROA.AssemblyInfo.cs +++ b/mROA/obj/Debug/net9.0/mROA.AssemblyInfo.cs @@ -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")]