encapsulate template logic
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using mROA.CodegenTools;
|
||||
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class EventBinderTemplate : TemplateView
|
||||
{
|
||||
private const string CallFilterTag = "callFilter";
|
||||
private const string TypeTag = "type";
|
||||
private const string EventNameTag = "eventName";
|
||||
private const string ParametersDeclarationTag = "parametersDeclaration";
|
||||
private const string CommandIdTag = "commandId";
|
||||
private const string TransferParametersTag = "transferParameters";
|
||||
|
||||
public EventBinderTemplate(TemplateDocument template) : base(template) { }
|
||||
|
||||
public void DefineCallFilter(string value)
|
||||
{
|
||||
Define(CallFilterTag, value);
|
||||
}
|
||||
|
||||
public void DefineType(string value)
|
||||
{
|
||||
Define(TypeTag, value);
|
||||
}
|
||||
|
||||
public void DefineEventName(string value)
|
||||
{
|
||||
Define(EventNameTag, value);
|
||||
}
|
||||
|
||||
public void DefineParametersDeclaration(string value)
|
||||
{
|
||||
Define(ParametersDeclarationTag, value);
|
||||
}
|
||||
|
||||
public void DefineCommandIdTag(string value)
|
||||
{
|
||||
Define(CommandIdTag, value);
|
||||
}
|
||||
|
||||
public void DefineTransferParameters(string value)
|
||||
{
|
||||
Define(TransferParametersTag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class IndexProviderTemplate : TemplateView
|
||||
{
|
||||
private const string TemplateFile = "IndexProvider.cstmpl";
|
||||
|
||||
private const string NamespaceTag = "namespace";
|
||||
private const string LevelTag = "level";
|
||||
private const string LenTag = "len";
|
||||
private const string IndexSpanTag = "indexSpan";
|
||||
private const string RemoteTypePairTag = "remoteTypePair";
|
||||
|
||||
public IndexProviderTemplate() : base(TemplateFile) { }
|
||||
|
||||
public void DefineNamespace(string value)
|
||||
{
|
||||
Define(NamespaceTag, value);
|
||||
}
|
||||
|
||||
public void DefineLevel(string value)
|
||||
{
|
||||
Define(LevelTag, value);
|
||||
}
|
||||
|
||||
public void DefineLen(string value)
|
||||
{
|
||||
Define(LenTag, value);
|
||||
}
|
||||
|
||||
public void InsertIndexSpan(string value)
|
||||
{
|
||||
Insert(IndexSpanTag, value);
|
||||
}
|
||||
|
||||
public void InsertRemoteTypePair(string value)
|
||||
{
|
||||
Insert(RemoteTypePairTag, value);
|
||||
}
|
||||
|
||||
public bool IsRemoteTypePairInserted()
|
||||
{
|
||||
return Inserted(RemoteTypePairTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using mROA.CodegenTools;
|
||||
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class InvokerTemplate : TemplateView
|
||||
{
|
||||
private const string IsVoidTag = "isVoid";
|
||||
private const string ReturnTypeTag = "returnType";
|
||||
private const string ParametersTypeTag = "parametersType";
|
||||
private const string SuitableTypeTag = "suitableType";
|
||||
private const string FuncInvokingTag = "funcInvoking";
|
||||
private const string IsTrustedTag = "isTrusted";
|
||||
|
||||
public InvokerTemplate(TemplateDocument template) : base(template) { }
|
||||
|
||||
public void DefineIsVoid(string value)
|
||||
{
|
||||
Define(IsVoidTag, value);
|
||||
}
|
||||
|
||||
public void DefineReturnType(string value)
|
||||
{
|
||||
Define(ReturnTypeTag, value);
|
||||
}
|
||||
|
||||
public void DefineParametersType(string value)
|
||||
{
|
||||
Define(ParametersTypeTag, value);
|
||||
}
|
||||
|
||||
public void DefineSuitableType(string value)
|
||||
{
|
||||
Define(SuitableTypeTag, value);
|
||||
}
|
||||
|
||||
public void DefineFuncInvoking(string value)
|
||||
{
|
||||
Define(FuncInvokingTag, value);
|
||||
}
|
||||
|
||||
public void DefineIsTrusted(string value)
|
||||
{
|
||||
Define(IsTrustedTag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class MethodRepoTemplate : TemplateView
|
||||
{
|
||||
private const string TemplateFile = "MethodRepo.cstmpl";
|
||||
|
||||
private const string SyncInvokerTemplate = "syncInvoker";
|
||||
private const string AsyncInvokerTemplate = "asyncInvoker";
|
||||
|
||||
private const string InvokerTag = "invoke";
|
||||
|
||||
public MethodRepoTemplate() : base(TemplateFile) { }
|
||||
|
||||
public void InsertInvoke(string value)
|
||||
{
|
||||
Insert(InvokerTag, value);
|
||||
}
|
||||
|
||||
public InvokerTemplate CloneInnerSyncInvoker()
|
||||
{
|
||||
var template = CloneInner(SyncInvokerTemplate);
|
||||
return new InvokerTemplate(template);
|
||||
}
|
||||
|
||||
public InvokerTemplate CloneInnerAsyncInvoker()
|
||||
{
|
||||
var template = CloneInner(AsyncInvokerTemplate);
|
||||
return new InvokerTemplate(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using mROA.CodegenTools;
|
||||
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public partial class ObjectBinderTemplate : TemplateView
|
||||
{
|
||||
private const string EventBinderTemplateTag = "eventBinderTemplate";
|
||||
|
||||
private const string TypeTag = "type";
|
||||
private const string EventBinderTag = "eventBinder";
|
||||
|
||||
public ObjectBinderTemplate(TemplateDocument template) : base(template) { }
|
||||
|
||||
public void DefineType(string value)
|
||||
{
|
||||
Define(TypeTag, value);
|
||||
}
|
||||
|
||||
public void InsertEventBinder(string value)
|
||||
{
|
||||
Insert(EventBinderTag, value);
|
||||
}
|
||||
|
||||
public EventBinderTemplate CloneInnerEventBinder()
|
||||
{
|
||||
var template = CloneInner(EventBinderTemplateTag);
|
||||
return new EventBinderTemplate(template);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class PartialInterfaceTemplate : TemplateView
|
||||
{
|
||||
private const string TemplateFile = "PartialInterface.cstmpl";
|
||||
|
||||
private const string NameTag = "name";
|
||||
private const string NamespaceTag = "namespace";
|
||||
private const string SignatureTag = "signature";
|
||||
|
||||
public PartialInterfaceTemplate() : base(TemplateFile) { }
|
||||
|
||||
public void DefineName(string value)
|
||||
{
|
||||
Define(NameTag, value);
|
||||
}
|
||||
|
||||
public void DefineNamespace(string value)
|
||||
{
|
||||
Define(NamespaceTag, value);
|
||||
}
|
||||
|
||||
public void InsertSignature(string value)
|
||||
{
|
||||
Insert(SignatureTag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class ProxyTemplate : TemplateView
|
||||
{
|
||||
private const string TemplateFile = "Proxy.cstmpl";
|
||||
|
||||
private const string ClassNameTag = "className";
|
||||
private const string OriginalNameTag = "originalName";
|
||||
private const string NamespaceNameTag= "namespaceName";
|
||||
private const string MethodsTag = "methods";
|
||||
|
||||
public ProxyTemplate() : base(TemplateFile) { }
|
||||
|
||||
public void DefineClassName(string value)
|
||||
{
|
||||
Define(ClassNameTag, value);
|
||||
}
|
||||
|
||||
public void DefineOriginalName(string value)
|
||||
{
|
||||
Define(OriginalNameTag, value);
|
||||
}
|
||||
|
||||
public void DefineNamespaceName(string value)
|
||||
{
|
||||
Define(NamespaceNameTag, value);
|
||||
}
|
||||
|
||||
public void InsertMethods(string value)
|
||||
{
|
||||
Insert(MethodsTag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public class RemoteTypeBinderTemplate : TemplateView
|
||||
{
|
||||
private const string TemplateFile = "RemoteTypeBinder.cstmpl";
|
||||
|
||||
private const string ObjectBinderTemplateTag = "objectBinderTemplate";
|
||||
private const string EventBinderTag = "eventBinder";
|
||||
|
||||
public RemoteTypeBinderTemplate() : base(TemplateFile) { }
|
||||
|
||||
public ObjectBinderTemplate CloneInnerObjectBinder()
|
||||
{
|
||||
var template = CloneInner(ObjectBinderTemplateTag);
|
||||
return new ObjectBinderTemplate(template);
|
||||
}
|
||||
|
||||
public void InsertEventBinder(string value)
|
||||
{
|
||||
Insert(EventBinderTag, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using mROA.CodegenTools;
|
||||
using mROA.CodegenTools.Reading;
|
||||
|
||||
namespace mROA.Codegen.Templates
|
||||
{
|
||||
public abstract class TemplateView
|
||||
{
|
||||
private readonly TemplateDocument _template;
|
||||
|
||||
protected TemplateView(string templateFile)
|
||||
{
|
||||
_template = TemplateReader.FromEmbeddedResource(templateFile);
|
||||
}
|
||||
|
||||
protected TemplateView(TemplateDocument template)
|
||||
{
|
||||
_template = template;
|
||||
}
|
||||
|
||||
public string Compile()
|
||||
{
|
||||
return _template.Compile();
|
||||
}
|
||||
|
||||
protected void Define(string tag, string value)
|
||||
{
|
||||
_template.AddDefine(tag, value);
|
||||
}
|
||||
|
||||
protected void Insert(string tag, string value)
|
||||
{
|
||||
_template.Insert(tag, value);
|
||||
}
|
||||
|
||||
protected bool Inserted(string tag)
|
||||
{
|
||||
return _template[$"{tag}+"] != null;
|
||||
}
|
||||
|
||||
protected TemplateDocument CloneInner(string tag)
|
||||
{
|
||||
return _template.CloneInnerTemplate(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user