style: 修改codegen命名
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Yi.Framework.CodeGen.Domain.Shared.Enums;
|
||||
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public class FieldTemplateHandler : TemplateHandlerBase, ITemplateHandler
|
||||
{
|
||||
public HandledTemplate Invoker(string str, string path)
|
||||
{
|
||||
var output = new HandledTemplate();
|
||||
output.TemplateStr = str.Replace("@field", BuildFields());
|
||||
output.BuildPath = path;
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成Fields
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string BuildFields()
|
||||
{
|
||||
StringBuilder fieldStrs = new StringBuilder();
|
||||
|
||||
|
||||
foreach (var field in Table.Fields)
|
||||
{
|
||||
var typeStr = typeof(FieldTypeEnum).GetFields().Where(x => x.Name == field.FieldType.ToString())?.FirstOrDefault().GetCustomAttribute<DisplayAttribute>().Name;
|
||||
|
||||
if (typeStr is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var nameStr = field.Name;
|
||||
|
||||
//添加备注
|
||||
if (!string.IsNullOrEmpty(field.Description))
|
||||
{
|
||||
var desStr = "/// <summary>\n" +
|
||||
$"///{field.Description}\n" +
|
||||
"/// </summary>\n";
|
||||
fieldStrs.AppendLine(desStr);
|
||||
}
|
||||
|
||||
//添加长度
|
||||
if (field.Length != 0)
|
||||
{
|
||||
var lengthStr = $"[SugarColumn(Length ={field.Length})]";
|
||||
fieldStrs.AppendLine(lengthStr);
|
||||
}
|
||||
|
||||
//添加可空类型
|
||||
string nullStr = "";
|
||||
if (field.IsRequired == false)
|
||||
{
|
||||
nullStr = "?";
|
||||
}
|
||||
|
||||
//添加字段
|
||||
var fieldStr = $"public {typeStr}{nullStr} {nameStr} {{ get; set; }}";
|
||||
|
||||
fieldStrs.AppendLine(fieldStr);
|
||||
}
|
||||
|
||||
return fieldStrs.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public class HandledTemplate
|
||||
{
|
||||
public string TemplateStr { get; set; }
|
||||
|
||||
public string BuildPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Yi.Framework.CodeGen.Domain.Entities;
|
||||
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public interface ITemplateHandler : ISingletonDependency
|
||||
{
|
||||
void SetTable(TableAggregateRoot table);
|
||||
HandledTemplate Invoker(string str, string path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public class ModelTemplateHandler : TemplateHandlerBase, ITemplateHandler
|
||||
{
|
||||
public HandledTemplate Invoker(string str, string path)
|
||||
{
|
||||
var output = new HandledTemplate();
|
||||
output.TemplateStr = str.Replace("@model", char.ToLowerInvariant(Table.Name[0]) + Table.Name.Substring(1)).Replace("@Model", char.ToUpperInvariant(Table.Name[0]) + Table.Name.Substring(1));
|
||||
output.BuildPath = path.Replace("@model", char.ToLowerInvariant(Table.Name[0]) + Table.Name.Substring(1)).Replace("@Model", char.ToUpperInvariant(Table.Name[0]) + Table.Name.Substring(1));
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public class NameSpaceTemplateHandler : TemplateHandlerBase, ITemplateHandler
|
||||
{
|
||||
public HandledTemplate Invoker(string str, string path)
|
||||
{
|
||||
var output = new HandledTemplate();
|
||||
output.TemplateStr = str.Replace("@namespace", "");
|
||||
output.BuildPath = path;
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using Yi.Framework.CodeGen.Domain.Entities;
|
||||
|
||||
namespace Yi.Framework.CodeGen.Domain.Handlers
|
||||
{
|
||||
public class TemplateHandlerBase
|
||||
{
|
||||
protected TableAggregateRoot Table { get; set; }
|
||||
|
||||
public void SetTable(TableAggregateRoot table)
|
||||
{
|
||||
Table = table;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user