.NET实体类生成器
来源:互联网 发布:货运软件有哪些 编辑:程序博客网 时间:2024/05/07 16:51
牛腩的视频中,提到实体类生成器,从网上下载下来的,一点儿也不精简。
下面自己编写一个.NET实体类生成器。
(C#)
在窗体上拖入一些控件:
最后如图:
Form1.cs[设计]:
Form1.cs代码:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;using System.Text.RegularExpressions ;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string ClassName1 = textBox1.Text.Trim(); string classexp1 = txtexp.Text.Trim(); string NameSpace1 = txtNameSapace.Text.Trim(); if (ClassName1.Length == 0) { MessageBox.Show("类名不能为空"); return; } sfdFile.FileName = ClassName1; if (sfdFile.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(sfdFile.FileName, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, Encoding.Default); if (radyou.Checked && txtNameSapace.Text.Trim() != null) { sw.WriteLine("nameSpace " + NameSpace1); sw.WriteLine("{"); } sw.WriteLine(" public class " + ClassName1); sw.WriteLine(" {"); foreach (DataGridViewRow Row in fdcontent.Rows) { if (Row.Cells[0].Value != null && Row.Cells[0].Value != null) { string propname = Row.Cells[0].Value.ToString(); string type = Row.Cells[1].Value.ToString(); //替换propname前一个或多个下划线,中间下划线不替换 sw.WriteLine(" private " + type + " " + propname + ";"); string propname1 = Regex.Replace(propname, "^_+", ""); //把propname首字母变为大写 string functionname = propname1.Substring(0, 1).ToUpper() + propname1.Substring(1); sw.WriteLine(" public " + type + " " + functionname); sw.WriteLine(" {"); sw.WriteLine(" get { return " + propname + "; }"); sw.WriteLine(" set { " + propname + " = value; }"); sw.WriteLine(" }"); } } sw.WriteLine("}"); if (radyou.Checked && txtNameSapace.Text.Trim() != null) { sw.WriteLine("}"); } sw.Close(); fs.Close(); MessageBox.Show("实体类创建成功!"); } } private void radwu_CheckedChanged(object sender, EventArgs e) { txtNameSapace.Visible = false; } private void radyou_CheckedChanged(object sender, EventArgs e) { txtNameSapace.Visible = true; } } }
Class1.cs代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace WindowsFormsApplication1{ class Class1 { private int id; public int Id { get { return id; } set { id = value; } } private string name; public string Name { get { return name; } set { name = value; } } }}
Program.cs代码:
using System;using System.Collections.Generic;using System.Linq;using System.Windows.Forms;namespace WindowsFormsApplication1{ static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); Class1 u = new Class1(); u.Id = 1; u.Name = "物业"; } }}
打包好的下载:点击打开链接
http://download.csdn.net/detail/wulingmin21/3947512
- .NET实体类生成器
- .NET实体类生成器 改
- C#实体类生成器
- 自制C#实体类生成器
- 【动软.Net代码生成器】连接MySQL生成C#的POCO实体类(Model)
- asp.net 实体类
- C# .NET 实体类
- ASP.NET:自定义实体类
- Android开发中使用fastJSON将json格式的数据快速解析生成实体类并附上实体类生成器
- 利用动软代码生成器 自动生成LINQ需要用的数据实体类
- 牛腩新闻系统(四)——类生成器生成实体代码
- 利用MyBatis生成器自动生成实体类、DAO接口和Mapping映射文件
- c# .net实体类序列化
- c#.net实体类序列化方法
- android 调用NET webservice返回实体类
- 深入.NET第二章实体类
- .net 获取实体类的属性
- 代码生成器与 .NET
- GDI 总结二: 位图的绘制
- 关于MSCHART插件的一些功能函数记录——Note on Dec. 20
- 推荐一款DataGridView的打印解决方案
- Android中悬浮窗口的实现原理和示例代码
- asp.net 文本框设为只读删除键返回上页
- .NET实体类生成器
- NSGeomerty.h
- 五金一险,你知多少?
- ARM开发板上iconv_open("utf-8", "gb2312") 调用失败的解决方法
- 线性表的顺序表示与实现
- CentOS5安装后的初期设定
- MySQL创建用户及授权的简单方法
- Git的初试心得
- jdk内存溢出监控