博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# model代码生成器
阅读量:4345 次
发布时间:2019-06-07

本文共 3813 字,大约阅读时间需要 12 分钟。

using System.Collections.Generic;using System.Text;    public class Class1    {        //传递 1.表名 2.列名 3.类型        public void GenerateModel(string TableName, string ColumnName, string TypeName) //生成Model        {            #region  数据库ID所对应的类型值            Dictionary
DicType = new Dictionary
(); DicType.Add(56, "int"); DicType.Add(231, "string"); #endregion #region 列名集合和数据ID Dictionary
DicColum = new Dictionary
(); DicColum.Add("DictID", 56); DicColum.Add("DictType", 231); DicColum.Add("ParentID", 56); DicColum.Add("Subtitle", 231); DicColum.Add("Sorting", 56); #endregion TypeName = "Model"; TableName = "TableName"; TableName = TableName + TypeName; StringBuilder sb = new StringBuilder(); sb.Append("using System;"); //引入命名空间 sb.Append("namespace "); //命名空间名字 sb.Append(TypeName + "{
"); sb.Append(" public partial class "); sb.Append(TableName + "{
"); sb.Append("public " + TableName + "(){}"); sb.Append("#region Model" + "\r\n"); //Begin #region //内容 foreach (var i in DicColum) { foreach (var j in DicType) { if (i.Value == j.Key) // DicColum的56== DicType的56 { sb.Append("private "); sb.Append(j.Value); sb.Append(" _"); //sb.Append(i.Key); //DicColumd的DictID //转换一下大小写在追加 sb.Append(i.Key.ToLower()); sb.Append(";\r\n"); } } } foreach (var i in DicColum) { foreach (var j in DicType) { if (i.Value == j.Key) // DicColum的56== DicType的56 { sb.Append("public "); sb.Append(j.Value); sb.Append(" "); sb.Append(i.Key); sb.Append("{\r\n"); //set{ _dicttype=value;} sb.AppendFormat("set{
{ _{0} =value;}}", i.Key.ToLower()); sb.AppendFormat("get{
{return _{0} ;}}", i.Key.ToLower()); sb.Append("\r\n}"); } } } #endregion sb.Append("\r\n" + "#endregion"); //End sb.Append("\r\n" + "}}"); //sb.AppendFormat("using System;namespace {0}{ public partial class Dictionary{1}{ public {1}(){}}}"); string ss = sb.ToString(); } public void GenerateDAL(string TableName, string ColumnName, string TypeName) { TypeName = "DAL"; TableName = "ClassName"; TableName = TableName + TypeName; StringBuilder sb = new StringBuilder(); sb.Append("using System;"); //引入命名空间 sb.Append("using System.Data;"); sb.Append("using System.Text;"); sb.Append("using System.Data.SqlClient;"); sb.Append("using System.Collections.Generic;"); sb.AppendFormat("namespace {0}\r\n{\r\n", TypeName); sb.AppendFormat(" public partial class {0}\r\n{\r\n", TableName); sb.AppendFormat("public {0}(){}", TableName); //构造函数 sb.AppendFormat("public int Add({0} model)\r\n{
{\r\n", "Model模型名称"); sb.Append("StringBuilder strSql = new StringBuilder();"); //这种方法不好---------终止 } }

 

转载于:https://www.cnblogs.com/enych/p/8808738.html

你可能感兴趣的文章
前端基础之BOM和DOM
查看>>
[T-ARA/筷子兄弟][Little Apple]
查看>>
编译Libgdiplus遇到的问题
查看>>
【NOIP 模拟赛】Evensgn 剪树枝 树形dp
查看>>
java学习笔记④MySql数据库--01/02 database table 数据的增删改
查看>>
两台电脑如何实现共享文件
查看>>
组合模式Composite
查看>>
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>