ControllerGenerator/Commands/DbControllerGenerator.cs
(开头部分) 7KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using CommonUtils;
using ControllerGenerator.Structs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ControllerGenerator.Commands
{
class DbControllerGenerator
{
public static void Handler(object sender, EventArgs e)
{
var document = EditorUtil.GetTextDocument();
var classCode = document.GetText();
if (classCode.IsEmpty())
{
EditorUtil.ShowMessage("请选中代码文件");
return;
}
if (!classCode.Contains(": DbEntity"))
{
EditorUtil.ShowMessage("请选中表结构文件:\r\n" + classCode);
return;
}
var className = StringUtil.GetBetween(classCode, "public class ", " : DbEntity", false);
//DbSet
var needMigration = false;
var dbFile = document.GetFullName().Combine("../../Database/Db.cs");
var dbCode = FileUtil.GetText(dbFile);
if (dbCode.IsNotEmpty())
{
var endMark = " }\r\n}";
var targetCode = " public DbSet<{}> {}s { get; set; }\r\n".Format(className, className);
if (!dbCode.Contains(targetCode))
{
dbCode = dbCode.Replace(endMark, "\r\n" + targetCode + endMark);
FileUtil.SaveTo(dbFile, dbCode);
needMigration = true;
}
}
var namespace_ = StringUtil.GetBetween(classCode, "namespace ", "\n", false).Trim();
if (namespace_.IsEmpty())
namespace_ = "DefaultNamespace";
var parentspace = namespace_;
if (parentspace.Contains('.'))
parentspace = parentspace.Substring(0, parentspace.LastIndexOf('.'));
//类注释
var classSchame = StringUtil.GetBetween(classCode, "[SwaggerSchema(", "public class", false);
classSchame = StringUtil.GetBetween(classSchame, "\"", "\"", false);
classCode = StringUtil.SubstringFrom(classCode, "class");
//注释+字段
var fields = new List<Field>();
var fieldSchames = StringUtil.GetBetweens(classCode, "SwaggerSchema", " { get; set; }", true);
foreach (var fieldSchame in fieldSchames)
后面还有 102 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。