parent
9083915b62
commit
edd82f249c
|
|
@ -99,7 +99,7 @@ namespace Luban.Job.Common.TypeVisitors
|
||||||
|
|
||||||
public string Accept(TMap type, string bufName, string fieldName)
|
public string Accept(TMap type, string bufName, string fieldName)
|
||||||
{
|
{
|
||||||
return $"{{ {bufName}.WriteSize({fieldName}.Count); foreach((var _k, var _v) in {fieldName}) {{ {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(this, bufName, "_v")} }} }}";
|
return $"{{ {bufName}.WriteSize({fieldName}.Count); foreach(var _e in {fieldName}) {{ {type.KeyType.Apply(this, bufName, "_e.Key")} {type.ValueType.Apply(this, bufName, "_e.Value")} }} }}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,49 +8,7 @@ using System.Collections.Generic;
|
||||||
namespace Luban.Job.Proto.Generate
|
namespace Luban.Job.Proto.Generate
|
||||||
{
|
{
|
||||||
[Render("cs")]
|
[Render("cs")]
|
||||||
class CsRender : RenderBase
|
class CsRender : TemplateRenderBase
|
||||||
{
|
{
|
||||||
protected override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderCsEnumClass(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefBean b)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/cs/bean");
|
|
||||||
var result = template.RenderCode(b);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefProto p)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/cs/proto");
|
|
||||||
var result = template.RenderCode(p);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefRpc r)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/cs/rpc");
|
|
||||||
var result = template.RenderCode(r);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string RenderStubs(string name, string module, List<DefProto> protos, List<DefRpc> rpcs)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/cs/stub");
|
|
||||||
var result = template.Render(new
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Namespace = module,
|
|
||||||
Protos = protos,
|
|
||||||
Rpcs = rpcs,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
using Luban.Job.Common.Defs;
|
||||||
|
using Luban.Job.Common.Generate;
|
||||||
|
using Luban.Job.Common.Utils;
|
||||||
|
using Luban.Job.Proto.Defs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Luban.Job.Proto.Generate
|
||||||
|
{
|
||||||
|
abstract class TemplateRenderBase : RenderBase
|
||||||
|
{
|
||||||
|
protected string RenderTemplateDir => (this.GetType().GetCustomAttributes(typeof(RenderAttribute), false)[0] as RenderAttribute).Name;
|
||||||
|
|
||||||
|
protected override string Render(DefEnum e)
|
||||||
|
{
|
||||||
|
return RenderUtil.RenderCsEnumClass(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Render(DefBean b)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/bean");
|
||||||
|
var result = template.RenderCode(b);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Render(DefProto p)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/proto");
|
||||||
|
var result = template.RenderCode(p);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string Render(DefRpc r)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/rpc");
|
||||||
|
var result = template.RenderCode(r);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string RenderStubs(string name, string module, List<DefProto> protos, List<DefRpc> rpcs)
|
||||||
|
{
|
||||||
|
var template = StringTemplateUtil.GetTemplate($"proto/{RenderTemplateDir}/stub");
|
||||||
|
var result = template.Render(new
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Namespace = module,
|
||||||
|
Protos = protos,
|
||||||
|
Rpcs = rpcs,
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
||||||
namespace Luban.Job.Proto.Generate
|
namespace Luban.Job.Proto.Generate
|
||||||
{
|
{
|
||||||
[Render("typescript")]
|
[Render("typescript")]
|
||||||
class TypescriptRender : RenderBase
|
class TypescriptRender : TemplateRenderBase
|
||||||
{
|
{
|
||||||
public override void Render(GenContext ctx)
|
public override void Render(GenContext ctx)
|
||||||
{
|
{
|
||||||
|
|
@ -64,48 +64,5 @@ namespace Luban.Job.Proto.Generate
|
||||||
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override string Render(DefEnum e)
|
|
||||||
{
|
|
||||||
return RenderUtil.RenderTypescriptEnumClass(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefBean b)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/typescript/bean");
|
|
||||||
var result = template.RenderCode(b);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefProto p)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/typescript/proto");
|
|
||||||
var result = template.RenderCode(p);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string Render(DefRpc r)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/typescript/rpc");
|
|
||||||
var result = template.RenderCode(r);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string RenderStubs(string name, string module, List<DefProto> protos, List<DefRpc> rpcs)
|
|
||||||
{
|
|
||||||
var template = StringTemplateUtil.GetTemplate("proto/typescript/stub");
|
|
||||||
var result = template.Render(new
|
|
||||||
{
|
|
||||||
Name = name,
|
|
||||||
Namespace = module,
|
|
||||||
Protos = protos,
|
|
||||||
Rpcs = rpcs,
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue