提高生产性工具
原来在上一家公司,整整一年都在做工具,提高生产性,那个项目特别巨大,所以总共为老东家节约了500K左右的美金。
(除了表扬之外,我个人什么好处都没有,领导们都升官发财了,郁闷)
到了新公司,也准备开发一些提高生产性的工具。最近在看NET MVC和Spring MVC的资料。所以想开发一个Model代码生成工具。
公司不能上Git,代码也刚开始写,所以暂时不拿出来了。逻辑很简单,博客园高手如云,看一下就知道我怎么写的了。
功能现在还很简单,以后完善。

软件的界面大概是这个样子的,验证这块只是开了个头罢了。
由于公司未来不知道做NET还是JAVA(或许都做),所以,这里NET和JAVA都对应了.
自动生成的代码也很简单,以后会扩展的。
C#的
using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace model.Models { public class AccountModel { #region "model" [DisplayName("用户名")] [Required(ErrorMessage = "项目名称不能缺少")] public string username { get; set; } [DisplayName("密码")] [Required(ErrorMessage = "项目名称不能缺少")] public string password { get; set; } #endregion } }JAVA的
package model; public class AccountModel { //用户名 private String username ; public void setusername(String username){ this.username = username; } public String getusername(){ return this.username; } //密码 private String password ; public void setpassword(String password){ this.password = password; } public String getpassword(){ return this.password; } }注意点:
关于MetaData,Java和C#有一些区别,例如 C# 字符 string ,Java 字符 String
这里有懂Java的人吗,Java有自动属性吗,set,get一大堆,看着不爽阿。好像Spring框架一定要这么写。。。
代码生成也很简单,就是字符串的操作,StringBuilder里面不停的AppendLine
using System; using System.IO; using System.Text; namespace DevKit.MVCTool { public static partial class ModelCodeGenerator { /// <summary> /// 缩进 /// </summary> private static int indent; private static string UsingSystem = "using System;"; private static bool NeedComponentModel = false; private static string UsingComponentModel = "using System.ComponentModel;"; private static bool NeedDataAnnotations = false; private static string UsingDataAnnotations = "using System.ComponentModel.DataAnnotations;"; /// <summary> /// 生成ModelCode /// </summary> /// <param></param> /// <param></param> internal static void GenerateCSharp(string filename, ModelInfo model) { StreamWriter codeWriter = new StreamWriter(filename, false); StringBuilder code = new StringBuilder(); //缩进用空格 char space = " ".ToCharArray()[0]; indent = 0; code.AppendLine(String.Empty); code.AppendLine("namespace " + model.ProjectName + ".Models"); code.AppendLine("{"); indent += 4; code.AppendLine(new string(space, indent) + "public class " + model.ModelName); code.AppendLine(new string(space, indent) + "{"); indent += 4; code.AppendLine(new string(space, indent) + "#region \"model\""); code.AppendLine(String.Empty); indent += 4; foreach (var item in model.Items) { if (!string.IsNullOrEmpty(item.DisplayName)) { //DisplayNameAsComment if (item.DisplayNameAsComment) { code.AppendLine(new string(space, indent) + "/// <summary>"); code.AppendLine(new string(space, indent) + "/// " + item.DisplayName); code.AppendLine(new string(space, indent) + "/// </summary>"); } //DisplayName code.AppendLine(new string(space, indent) + "[DisplayName(\"" + item.DisplayName + "\")]"); NeedComponentModel = true; } if (item.Required) { //Required Without Error Message if (!String.IsNullOrEmpty(item.ErrorMsgForRequired)) { code.AppendLine(new string(space, indent) + "[Required(ErrorMessage = \"" + item.ErrorMsgForRequired + "\")]"); } else { code.AppendLine(new string(space, indent) + "[Required]"); } NeedDataAnnotations = true; } code.AppendLine(new string(space, indent) + "public @type @name { get; set; }" .Replace("@type", Common.DotNet.MetaData[item.DataType]) .Replace("@name", item.Name) ); code.AppendLine(String.Empty); } indent -= 4; code.AppendLine(new string(space, indent) + "#endregion"); indent -= 4; code.AppendLine(new string(space, indent) + "}"); indent -= 4; code.AppendLine("}"); codeWriter.WriteLine(UsingSystem); if (NeedComponentModel) codeWriter.WriteLine(UsingComponentModel); if (NeedDataAnnotations) codeWriter.WriteLine(UsingDataAnnotations); codeWriter.Write(code); codeWriter.Close(); } } }这种工具,小项目里面其实真心没有什么作用,大项目,需要很严格的编码规范,然后项目非常多的,价值就体现出来了。
所有代码编码规则可以统一了,做设计的人,直接用工具作设计即可,然后支持从Excel导入导出,又是一个提高生产性的措施。
设计人员完成这样的表格,然后,工具直接读取Excel文件,生成代码,这个是我的目标.
关注点分离,让设计模型规则的人,做设计,开发者关注BL的开发.

欢迎大家提需求。。。
更新:
我还希望能做这样一个路由配置功能,这些功能,其实更对的想给设计人员使用,或者能够将大家的时间从记忆代码写法中解放出来.
我喜欢可视化的东西,目标是做一个设计书到代码的自动工具.当然,我承认,不可能做到完全不靠手工编码,但是希望这个比例能够减少很多.
人,应该去做更加需要思考的工作.
关注点分离,让设计路由的人,统筹管理路由规则.

相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://www.juheyunku.com/jiaob/net/10638.shtml
相关文章
热门TAG
命令 外链 企业网站 白帽 php 织梦教程 dedecms修改内容 javascript 织梦 功能 标签 调用 详解 技巧 权重 服务器 网站流量 Dedecms 织梦cms HTML tags标签 python jquery教程 jquery windows 蜘蛛 搜索引擎 网站收录 JSP 实例解析最新文章
-
如何给asp.net core写个中间
时间:2021-01-03
-
.Net微信网页开发解决用户
时间:2021-01-03
-
c++中Socket通信函数之WSAS
时间:2020-12-29
-
提高生产性工具
时间:2020-12-29
-
全新的membership框架Asp.ne
时间:2020-12-29
-
不用找了,比较全的signal
时间:2020-12-29
-
计算字符串中每种字符出
时间:2020-12-29
-
EntityFramework 5.0 CodeFirst 教
时间:2020-12-29
热门文章
-
.NET 开发环境搭建图文详解
时间:2020-12-27
-
Windows下Visual Studio 2017安装配置方法图文教
时间:2020-12-23
-
.Net微信网页开发解决用户在不同公众号或
时间:2021-01-03
-
oracle 11g rac安装之grid报错解决
时间:2020-12-28
-
ASP.NET Core 3.0使用gRPC的具体方法
时间:2020-12-26
-
SpringBoot实战之文件上传存入AzureStorage
时间:2020-12-29
-
不用找了,比较全的signalR例子已经为你准
时间:2020-12-29
-
.NET Core3.1编写混合C++程序
时间:2020-12-26
-
Oracle的卸载
时间:2020-12-28
-
计算字符串中每种字符出现的次数[Dicti
时间:2020-12-29
