diff --git a/mROA.Codegen/RemoteEndpoint.cstmpl b/mROA.Codegen/RemoteEndpoint.cstmpl
index f703b0a..8a2541a 100644
--- a/mROA.Codegen/RemoteEndpoint.cstmpl
+++ b/mROA.Codegen/RemoteEndpoint.cstmpl
@@ -7,9 +7,11 @@ using mROA.Abstract;
namespace
{
- partial class : RemoteObjectBase,
+ partial class
+ : RemoteObjectBase,
{
- public (int id, IRepresentationModule representationModule) : base(id, representationModule)
+ public (int id, IRepresentationModule representationModule)
+ : base(id, representationModule)
{
}
diff --git a/mROA.Codegen/RemoteTypeBinder.cstmpl b/mROA.Codegen/RemoteTypeBinder.cstmpl
new file mode 100644
index 0000000..e51cfc4
--- /dev/null
+++ b/mROA.Codegen/RemoteTypeBinder.cstmpl
@@ -0,0 +1,22 @@
+//
+using System.Collections.Generic;
+using System.Reflection;
+using System;
+using mROA.Abstract;
+using mROA.Implementation.Backend;
+using mROA.Implementation;
+
+namespace mROA.Codegen
+{
+ public sealed class RemoteTypeBinder
+ {
+ static RemoteTypeBinder(){
+ RemoteContextRepository.RemoteTypes = new Dictionary {
+ ,
+ };
+ ContextRepository.EventBinders = new object[] {
+
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/mROA.Codegen/Tools/TemplateDocument.cs b/mROA.Codegen/Tools/TemplateDocument.cs
index 6567006..b7ea584 100644
--- a/mROA.Codegen/Tools/TemplateDocument.cs
+++ b/mROA.Codegen/Tools/TemplateDocument.cs
@@ -9,7 +9,7 @@ namespace mROA.CodegenTools
{
public List Parts { get; set; } = new List();
public object AdditionalContext { get; set; }
- public ITagged this[string tag] => Parts.OfType().FirstOrDefault(i => i.Tag == tag);
+ public ITagged? this[string tag] => Parts.OfType().FirstOrDefault(i => i.Tag == tag);
public void Insert(string tag, object value)
{
diff --git a/mROA.Codegen/mROA.Codegen.csproj b/mROA.Codegen/mROA.Codegen.csproj
index 1d06379..da1b5ae 100644
--- a/mROA.Codegen/mROA.Codegen.csproj
+++ b/mROA.Codegen/mROA.Codegen.csproj
@@ -35,6 +35,7 @@
+
diff --git a/mROA.Codegen/mROASourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs
index 85edf25..2b61c78 100644
--- a/mROA.Codegen/mROASourceGenerator.cs
+++ b/mROA.Codegen/mROASourceGenerator.cs
@@ -23,6 +23,7 @@ namespace mROA.Codegen
private TemplateDocument MethodRepoTemplate;
private TemplateDocument ClassTemplateOriginal;
private TemplateDocument ClassTemplate;
+ private TemplateDocument BinderTemplate;
private static Predicate ParameterFilter =
i => i.Type.Name is "CancellationToken" or "RequestContext";
@@ -34,6 +35,7 @@ namespace mROA.Codegen
{
MethodRepoTemplate = TemplateReader.FromEmbeddedResource("MethodRepo.cstmpl");
ClassTemplateOriginal = TemplateReader.FromEmbeddedResource("RemoteEndpoint.cstmpl");
+ BinderTemplate = TemplateReader.FromEmbeddedResource("RemoteTypeBinder.cstmpl");
}
public void Execute(GeneratorExecutionContext context)
@@ -66,7 +68,7 @@ namespace mROA.Codegen
GenerateCode(context, context.Compilation, interfaces.ToImmutableArray());
}
- catch (Exception)
+ catch (Exception e)
{
Console.WriteLine("ERROR: Unable to load method repository");
}
@@ -81,8 +83,7 @@ namespace mROA.Codegen
// var test = asm.GetManifestResourceStream("mROA.Codegen.test.tpt");
// var reader = new StreamReader(test);
// var allText = reader.ReadToEnd();
- var frontendContextRepo = new List();
- var eventBinders = new List();
+
List totalMethods = new List();
@@ -162,7 +163,7 @@ namespace mROA.Codegen
}
}
- GenerateEventImplementation(classSymbol, invokers, declaredMethods, context, eventBinders);
+ GenerateEventImplementation(classSymbol, invokers, context);
ClassTemplate.AddDefine("className", className);
ClassTemplate.AddDefine("originalName", originalName);
@@ -175,7 +176,7 @@ namespace mROA.Codegen
#if !DONT_ADD
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
#endif
- frontendContextRepo.Add(
+ BinderTemplate.Insert("remoteTypePair",
$"{{ typeof({classSymbol.ToDisplayString()}), typeof({namespaceName}.{className}) }}");
}
@@ -193,37 +194,16 @@ namespace mROA.Codegen
#endif
}
- if (frontendContextRepo.Count != 0)
+ if (BinderTemplate["remoteTypePair+"] != null)
{
- var fronendRepoCode = @$"//
-using System.Collections.Generic;
-using System.Reflection;
-using System;
-using mROA.Abstract;
-using mROA.Implementation.Backend;
-using mROA.Implementation;
-
-namespace mROA.Codegen
-{{
- public sealed class RemoteTypeBinder
- {{
- static RemoteTypeBinder(){{
- RemoteContextRepository.RemoteTypes = new Dictionary {{
- {string.Join(", \r\n\t\t\t", frontendContextRepo)}}};
- ContextRepository.EventBinders = new object[] {{
- {string.Join(",\r\n\t\t\t", eventBinders)}}};
- }}
- }}
-}}
-";
+ var fronendRepoCode = BinderTemplate.Compile();
#if !DONT_ADD
context.AddSource("RemoteTypeBinder.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8));
#endif
}
}
- private void GenerateEventImplementation(INamedTypeSymbol classSymbol, List invokers,
- List declaredMethods, GeneratorExecutionContext context, List binders)
+ private void GenerateEventImplementation(INamedTypeSymbol classSymbol, List invokers, GeneratorExecutionContext context)
{
var events = classSymbol.AllInterfaces.Add(classSymbol).SelectMany(i => i.GetMembers())
.OfType().ToList();
@@ -263,7 +243,8 @@ namespace {classSymbol.ContainingNamespace.ToDisplayString()}
{string.Join("\r\n", singleEventBinder)}
}}
}}";
- binders.Add(binder);
+ BinderTemplate.Insert("eventBinder", binder);
+
#if !DONT_ADD
context.AddSource($"{classSymbol.Name}.g.cs", SourceText.From(partialInterface, Encoding.UTF8));
#endif