添加代码生成器模块service实现

This commit is contained in:
橙子
2023-01-03 20:06:16 +08:00
parent 53b4674da4
commit 62c5470efe
8 changed files with 119 additions and 538 deletions

View File

@@ -3,40 +3,33 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Helper;
namespace Yi.Framework.Template.Abstract
{
public abstract class AbstractTemplateProvider : ITemplateProvider
{
public string BuildPath { get; set; }
public string TemplatePath { get; set; }
public string BakPath { get; set; }
private Dictionary<string, string> TemplateDic { get; set; }
public virtual string? BuildPath { get; set; }
public string? TemplatePath { get; set; }
public string? BakPath { get; set; }
protected Dictionary<string, string> TemplateDic { get; set; } = new Dictionary<string, string>();
public void Bak() {
}
public abstract void Bak();
public virtual void Build()
{
var templateData = GetTemplateData();
foreach (var ky in TemplateDic)
{
templateData = templateData.Replace(ky.Key, ky.Value);
}
File.WriteAllText(BuildPath, templateData);
}
public abstract void Build();
protected virtual string GetTemplateData()
{
if (TemplatePath is null)
{
throw new ArgumentNullException(nameof(TemplatePath));
}
return File.ReadAllText(TemplatePath);
}
protected void AddTemplateDic(string oldStr, string newStr)
protected void AddTemplateDic(string oldStr, string newStr)
{
TemplateDic=new Dictionary<string, string>();
TemplateDic.Add(oldStr, newStr);
}
}