c#代码生成器,生成代码可用于Web及Winform编程,可批量导出代码,导出代码直接拷贝到VS中就可以使用,支持MSSqlServer,Oracle数据库.生成UI、BLL、DAL、MODEL;我做.net开发3年,一直都用这个生成器,觉得很好用,分享给大家;希望该工具能帮到你!
1.代码生成灵活,根据用户所编辑的模板生成代码。
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ToolFunction;
using System.Data;
using CSScriptLibrary;
using Microsoft.CSharp;
using System.Reflection;
using System.Windows.Forms;
namespace AUTOCODE
{
////// 测试类
///public class @GetClassName(SourceTable)
{
@InitProperty(SourceTable)
}
}
#START@GetCamelCaseName
public static string GetCamelCaseName(string value)
{
return value.ToLower();
}
#END
#START@ConvertFirstCharToUpper
public static string ConvertFirstCharToUpper(string value)
{
return value.Substring(0, 1).ToUpper() + value.Substring(1);
}
#END
#START@InitProperty
///<summary>/// 生成属性代码
///</summary>///<param name="p_dtSource">数据源</param>///<returns>字符串</returns>public static string InitProperty(DataTable p_dtSource)
{
string _strLine = "";
foreach (DataColumn item in p_dtSource.Columns)
{
_strLine += "\n private " + GetCSharpVariableType(item) + " " + item.ColumnName.ToLower() + ";";
_strLine += "\n" + "public " + GetCSharpVariableType(item) + " " + GetPropertyName(item.ColumnName);
_strLine += "\n" + "{ ";
_strLine += "\n" + "get { return " + item.ColumnName.ToLower() + ";}";
_strLine += "\n" + "set {" + item.ColumnName.ToLower() + "= value;}";
_strLine += "\n" + "}";
}
return _strLine;
}
#END
#START@GetClassName
///<summary>/// 根据表生成类的名字
///</summary>///<param name="p_dtTable">表</param>///<returns></returns>public static string @GetClassName(DataTable p_dtTable)
{
if (p_dtTable == null)
{
return null;
}
string _strTemp = p_dtTable.TableName.Substring(0, 1).ToUpper() + p_dtTable.TableName.Substring(1).ToLower();
return _strTemp;
}
#END
#START@GetPropertyName
///<summary>/// 根据表名生成类
///</summary>///<param name="p_strName"></param>///<returns></returns>public static string GetPropertyName(string p_strName)
{
if (p_strName == null)
{
return null;
}
if (p_strName.Length == 1)
{
return p_strName.ToLower();
}
return p_strName.Substring(0, 1).ToUpper() + p_strName.Substring(1).ToLower();
}
#END
#START@GetLowerCaseName
public static string GetLowerCaseName(string value)
{
return value.ToLower();
}
#END
#START@GetCSharpVariableType
///<summary>/// 根据表的列转化代码中的数据类型
///</summary>///<param name="p_dcColumn">表列</param>///<returns></returns>public static string GetCSharpVariableType(DataColumn p_dcColumn)
{
if (p_dcColumn.ColumnName.EndsWith("TypeCode")) return p_dcColumn.ColumnName;
switch (p_dcColumn.DataType.Name.ToString())
{
case "AnsiString": return "string";
case "AnsiStringFixedLength": return "string";
case "Binary": return "byte[]";
case "Boolean": return "bool";
case "Byte": return "byte";
case "Currency": return "decimal";
case "Date": return "DateTime";
case "DateTime": return "DateTime";
case "Decimal": return "decimal";
case "Double": return "double";
case "Guid": return "Guid";
case "Int16": return "short";
case "Int32": return "int";
case "Int64": return "long";
case "Object": return "object";
case "SByte": return "sbyte";
case "Single": return "float";
case "String": return "string";
case "StringFixedLength": return "string";
case "Time": return "TimeSpan";
case "UInt16": return "ushort";
case "UInt32": return "uint";
case "UInt64": return "ulong";
case "VarNumeric": return "decimal";
default:
{
return "__UNKNOWN__";
}
}
}
#END
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ToolFunction;
using System.Data;
using CSScriptLibrary;
using Microsoft.CSharp;
using System.Reflection;
using System.Windows.Forms;
namespace AUTOCODE
{
////// 测试类
///public class @GetClassName(SourceTable)
{
@InitProperty(SourceTable)
}
}
#START@GetCamelCaseName
public static string GetCamelCaseName(string value)
{
return value.ToLower();
}
#END
#START@ConvertFirstCharToUpper
public static string ConvertFirstCharToUpper(string value)
{
return value.Substring(0, 1).ToUpper() + value.Substring(1);
}
#END
#START@InitProperty
///<summary>/// 生成属性代码
///</summary>///<param name="p_dtSource">数据源</param>///<returns>字符串</returns>public static string InitProperty(DataTable p_dtSource)
{
string _strLine = "";
foreach (DataColumn item in p_dtSource.Columns)
{
_strLine += "\n private " + GetCSharpVariableType(item) + " " + item.ColumnName.ToLower() + ";";
_strLine += "\n" + "public " + GetCSharpVariableType(item) + " " + GetPropertyName(item.ColumnName);
_strLine += "\n" + "{ ";
_strLine += "\n" + "get { return " + item.ColumnName.ToLower() + ";}";
_strLine += "\n" + "set {" + item.ColumnName.ToLower() + "= value;}";
_strLine += "\n" + "}";
}
return _strLine;
}
#END
#START@GetClassName
///<summary>/// 根据表生成类的名字
///</summary>///<param name="p_dtTable">表</param>///<returns></returns>public static string @GetClassName(DataTable p_dtTable)
{
if (p_dtTable == null)
{
return null;
}
string _strTemp = p_dtTable.TableName.Substring(0, 1).ToUpper() + p_dtTable.TableName.Substring(1).ToLower();
return _strTemp;
}
#END
#START@GetPropertyName
///<summary>/// 根据表名生成类
///</summary>///<param name="p_strName"></param>///<returns></returns>public static string GetPropertyName(string p_strName)
{
if (p_strName == null)
{
return null;
}
if (p_strName.Length == 1)
{
return p_strName.ToLower();
}
return p_strName.Substring(0, 1).ToUpper() + p_strName.Substring(1).ToLower();
}
#END
#START@GetLowerCaseName
public static string GetLowerCaseName(string value)
{
return value.ToLower();
}
#END
#START@GetCSharpVariableType
///<summary>/// 根据表的列转化代码中的数据类型
///</summary>///<param name="p_dcColumn">表列</param>///<returns></returns>public static string GetCSharpVariableType(DataColumn p_dcColumn)
{
if (p_dcColumn.ColumnName.EndsWith("TypeCode")) return p_dcColumn.ColumnName;
switch (p_dcColumn.DataType.Name.ToString())
{
case "AnsiString": return "string";
case "AnsiStringFixedLength": return "string";
case "Binary": return "byte[]";
case "Boolean": return "bool";
case "Byte": return "byte";
case "Currency": return "decimal";
case "Date": return "DateTime";
case "DateTime": return "DateTime";
case "Decimal": return "decimal";
case "Double": return "double";
case "Guid": return "Guid";
case "Int16": return "short";
case "Int32": return "int";
case "Int64": return "long";
case "Object": return "object";
case "SByte": return "sbyte";
case "Single": return "float";
case "String": return "string";
case "StringFixedLength": return "string";
case "Time": return "TimeSpan";
case "UInt16": return "ushort";
case "UInt32": return "uint";
case "UInt64": return "ulong";
case "VarNumeric": return "decimal";
default:
{
return "__UNKNOWN__";
}
}
}
#END
2.提供模板文件管理模块。
3.提供基础配置模块,方便数据库连接,导出目录设置。
4.模板包含属性说明区,函数注册区,静态文本区,动态函数区。规范严谨,易于书写编辑。
5.通过动态编译实现了模板中可添加c#函数,对数据源进行动态操作。
6.多种文件格式导出(只有想生成的文件与数据表有紧密联系,均可根据动态函数区的代码进行代码生成)
未完成功能
支持SqlServer、mysql.
76.4M / 03-25
立即下载55M / 06-05
立即下载237.9M / 04-13
立即下载140.5M / 03-06
立即下载900.9M / 03-02
立即下载96.2M / 07-06
立即下载311.2M / 07-06
立即下载335M / 07-06
立即下载200M / 07-06
立即下载413.8M / 07-06
立即下载353.9M / 06-05
立即下载131.8M / 04-13
立即下载230.8M / 03-03
立即下载195.6M / 03-03
立即下载165.4M / 03-03
立即下载45.6M / 09-08
立即下载665.2M / 07-06
立即下载2.84G / 07-06
立即下载93M / 07-06
立即下载338.3M / 07-06
立即下载1.38G / 07-26
立即下载488.3M / 07-16
立即下载109.8M / 06-03
立即下载142M / 01-08
立即下载1.2M / 11-23
立即下载548.8M / 04-13
立即下载1.6M / 04-13
立即下载1.48G / 03-18
立即下载646.6M / 03-03
立即下载133.7M / 03-03
立即下载325.8M / 06-07
立即下载60M / 04-29
立即下载254M / 04-25
立即下载659M / 04-23
立即下载1M / 12-26
立即下载253.4M / 12-08
立即下载253M / 12-08
立即下载1.19G / 11-16
立即下载110.5M / 04-23
立即下载26.7M / 03-16
立即下载488.3M / 07-16
立即下载248.9M / 12-08
立即下载248.9M / 12-08
立即下载201.2M / 04-13
立即下载100.6M / 03-06
立即下载148.9M / 03-06
立即下载1.12G / 07-06
立即下载1.25G / 07-06
立即下载9.48G / 07-06
立即下载50KB / 07-06
立即下载116.2M / 04-10
立即下载1.92G / 04-17
立即下载201.5M / 04-13
立即下载7.31G / 07-01
立即下载94.3M / 07-06
立即下载2.48G / 07-06
立即下载7.63G / 07-06
立即下载1M / 07-06
立即下载778.1M / 07-06
立即下载509.7M / 07-06
立即下载561.8M / 07-11
立即下载1.32G / 01-19
立即下载72M / 07-06
立即下载548.7M / 07-06
立即下载1.00G / 07-06
立即下载9.13G / 07-06
立即下载126.2M / 07-06
立即下载72M / 07-06
立即下载105.1M / 07-06
立即下载132M / 07-06
立即下载