当前位置: 首页 > news >正文

wordpress 建站免费谷歌广告上海有限公司官网

wordpress 建站免费,谷歌广告上海有限公司官网,建筑八大员证书怎么查询,电子商务网站建设需要哪些步骤通过替换字符串的方式生成代码&#xff0c;其他代码也可以通这种方式生成 直接上代码 设置模板 将这几个模板文件设置为&#xff1a;嵌入资源 模板内容&#xff1a; using SqlSugar;namespace {Namespace}.Domain.Admin.{ModelName}; /// <summary> /// {TableDisplay…

通过替换字符串的方式生成代码,其他代码也可以通这种方式生成
直接上代码

设置模板

在这里插入图片描述
将这几个模板文件设置为:嵌入资源
在这里插入图片描述
模板内容:

using SqlSugar;namespace {Namespace}.Domain.Admin.{ModelName};
/// <summary>
/// {TableDisplayName}
///</summary>
[SugarTable("{TableName}")]
public class {ModelName}Entity
{{AttributeList}
}

生成代码

 /// <summary>/// 预览代码/// </summary>/// <param name="currentTableName">表名</param>/// <returns></returns>[HttpGet]public ProviewCodeOutput PreviewCode(string currentTableName){//我是在其他类里面生成的代码,所以通过dll加载嵌入的资源// 通过 DLL 加载资源 var assemblyPath = Path.Combine(AppContext.BaseDirectory, "XR.Host.dll");var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(a => a.Contains("ModelTemplate.txt"));var file = assembly.GetManifestResourceStream(resourceName);//实体模板var modelTemplate = new StreamReader(file).ReadToEnd();//仓储接口模板var IrepostoryTemplate = new StreamReader(assembly.GetManifestResourceStream(assembly.GetManifestResourceNames().FirstOrDefault(a => a.Contains("IRepositoryTemplate.txt")))).ReadToEnd();//仓储接口模板var repostoryTemplate = new StreamReader(assembly.GetManifestResourceStream(assembly.GetManifestResourceNames().Where(a => a.Contains("RepositoryClassTemplate.txt")).First())).ReadToEnd();var orm = LazyGetRequiredService<IUserRepository>().Orm;var table = orm.DbMaintenance.GetTableInfoList(true);//命名空间var Namespace = Assembly.GetExecutingAssembly().GetName().Name;var parentPath = new DirectoryInfo(Environment.CurrentDirectory).Parent + $"\\{Namespace}";var result = new ProviewCodeOutput();foreach (var tableInfo in table){if (tableInfo.Name == currentTableName){var modelName = tableInfo.Name.Replace("SYS_", "").Replace("TB_", "").Replace("TN_", "");modelName = ConvertToCamelCase(modelName);var tableColumn = orm.DbMaintenance.GetColumnInfosByTableName(tableInfo.Name);var attributes = BuildColumn(tableColumn);//通过替换字符串的方式生成代码result.ModalCode = modelTemplate.Replace("{Namespace}", Namespace).Replace("{ModelName}", modelName).Replace("{TableName}", tableInfo.Name).Replace("{TableDisplayName}", tableInfo.Description).Replace("{AttributeList}", attributes);}}return result;}private string BuildColumn(List<DbColumnInfo> columnInfos){var attributes = new StringBuilder();foreach (var columnInfo in columnInfos){attributes.Append("\r\n    /// <summary>");attributes.Append($"\r\n   /// {columnInfo.ColumnDescription}");attributes.Append("\r\n    /// </summary>");attributes.Append($"\r\n   [SugarColumn({(columnInfo.IsPrimarykey ? "IsPrimaryKey = true," : "")} ColumnName = \"{columnInfo.DbColumnName}\", {(columnInfo.IsNullable ? "IsNullable = true," : "")} ColumnDescription = \"{columnInfo.ColumnDescription}\")]");attributes.Append($"\r\n   public {SetDataType(columnInfo.DataType)}{(columnInfo.IsNullable ? "?" : "")} {ConvertToCamelCase(columnInfo.DbColumnName)} {{ get; set; }}");}return attributes.ToString();}private string SetDataType(string dataType){dataType = dataType.ToLower();var result = dataType;switch (dataType){case "int32":result = typeof(int).Name;break;case "int64":result = typeof(int).Name;break;case "datetime":result = typeof(DateTime).Name;break;}return result;}/// <summary>/// 将驼峰转换为字符串/// </summary>/// <param name="input"></param>/// <returns></returns>private string ConvertToCamelCase(string input){if (string.IsNullOrEmpty(input))return input;var text = input.Split('_');var camelTxt = "";TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;foreach (var c in text){camelTxt += textInfo.ToTitleCase(c.ToLower());}return camelTxt;}
http://www.hengruixuexiao.com/news/54037.html

相关文章:

  • 免费的素材网站推荐百度不收录网站
  • 网站建设要域名和什么互动营销用在哪些推广上面
  • 信用门户网站建设观摩百度搜索关键词优化
  • 厂字型布局网站2020十大网络热词
  • 网站咨询弹窗是怎么做的百度人工客服在线咨询
  • 邢台做移动网站多少钱seo综合检测
  • 做淘客网站的推广神器app
  • 自助建站网站源码电子商务网站建设规划方案
  • 信通网站开发中心seo网站
  • 日本人真人做真爱的网站市场调研报告怎么写
  • 北京好的网站建设搜索量排行
  • 网站建设书籍推荐长沙大型网站建设公司
  • 网站页面吸引力网络推广平台代理
  • 网站后台无法上传图片制作网页
  • 东莞网站页设计制作域名站长工具
  • 旅游网站建设方案的总结百度首页网站推广多少钱一年
  • 2013年以前pc网站建设2024年疫情还会封控吗
  • 有哪些建设网站的大公司百度问答优化
  • 徐州网站公司社群营销的案例
  • 眉山市住房和城乡建设局网站网址收录入口
  • 网站开发文章怎么分类网站友链查询源码
  • wordpress+培训模板seo的基本步骤包括哪些
  • 公司网站最新版营销培训
  • 做淘宝一件代发的网站邵阳seo优化
  • 赚钱软件排行流程优化四个方法
  • 广州网站建设报价苏州网站建设哪家靠谱
  • jsp网站建设技术案例手机搜索引擎排名
  • 如何免费找精准客户广州seo网站优化培训
  • 让人做网站需要准备什么条件厦门网站流量优化价格
  • 网站开发 兼职项目免费域名注册