extract TemplateDocument loading logic

This commit is contained in:
Ivan Ansimov
2025-07-14 20:01:40 +03:00
parent 26cdf86bd6
commit abc3bda88e
2 changed files with 93 additions and 58 deletions
+49
View File
@@ -0,0 +1,49 @@
using System;
using mROA.CodegenTools;
using mROA.CodegenTools.Reading;
namespace mROA.Codegen
{
public class CodeTemplate
{
private const string MethodRepoTemplateName = "MethodRepo.cstmpl";
private const string ProxyTemplateName = "Proxy.cstmpl";
private const string RemoteTypeBinderTemplateName = "RemoteTypeBinder.cstmpl";
private const string PartialInterfaceTemplateName = "PartialInterface.cstmpl";
private const string IndexProviderTemplateName = "IndexProvider.cstmpl";
private const string SyncInvokerTag = "syncInvoker";
private TemplateDocument? _proxy;
private TemplateDocument? _indexerProvider;
private TemplateDocument? _remoteTypeBinder;
private TemplateDocument? _partialInterface;
private TemplateDocument? _methodRepo;
private TemplateDocument? _methodInvoker;
public TemplateDocument Proxy => _proxy
?? throw new InvalidOperationException();
public TemplateDocument IndexerProvider => _indexerProvider
?? throw new InvalidOperationException();
public TemplateDocument RemoteTypeBinder => _remoteTypeBinder
?? throw new InvalidOperationException();
public TemplateDocument PartialInterface => _partialInterface
?? throw new InvalidOperationException();
public TemplateDocument MethodRepo => _methodRepo
?? throw new InvalidOperationException();
public TemplateDocument MethodInvoker => _methodInvoker
?? throw new InvalidOperationException();
public void LoadTemplates()
{
_proxy = TemplateReader.FromEmbeddedResource(ProxyTemplateName);
_indexerProvider = TemplateReader.FromEmbeddedResource(IndexProviderTemplateName);
_remoteTypeBinder = TemplateReader.FromEmbeddedResource(RemoteTypeBinderTemplateName);
_partialInterface = TemplateReader.FromEmbeddedResource(PartialInterfaceTemplateName);
_methodRepo = TemplateReader.FromEmbeddedResource(MethodRepoTemplateName);
var innerMethodSection = MethodRepo[SyncInvokerTag] as InnerTemplateSection
?? throw new InvalidOperationException();
_methodInvoker = innerMethodSection.InnerTemplate;
}
}
}