Частично переписан RemoteTypeBinder
This commit is contained in:
@@ -23,6 +23,7 @@ namespace mROA.Codegen
|
||||
private TemplateDocument MethodRepoTemplate;
|
||||
private TemplateDocument ClassTemplateOriginal;
|
||||
private TemplateDocument ClassTemplate;
|
||||
private TemplateDocument BinderTemplate;
|
||||
|
||||
private static Predicate<IParameterSymbol> 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<string>();
|
||||
var eventBinders = new List<string>();
|
||||
|
||||
List<IMethodSymbol> totalMethods = new List<IMethodSymbol>();
|
||||
|
||||
|
||||
@@ -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 = @$"// <auto-generated/>
|
||||
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<Type, Type> {{
|
||||
{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<string> invokers,
|
||||
List<string> declaredMethods, GeneratorExecutionContext context, List<string> binders)
|
||||
private void GenerateEventImplementation(INamedTypeSymbol classSymbol, List<string> invokers, GeneratorExecutionContext context)
|
||||
{
|
||||
var events = classSymbol.AllInterfaces.Add(classSymbol).SelectMany(i => i.GetMembers())
|
||||
.OfType<IEventSymbol>().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
|
||||
|
||||
Reference in New Issue
Block a user