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
///
//////數據源///
{
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
///
//////表///
{
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
///
/////////
{
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
///
//////表列///
{
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
///
//////數據源///
{
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
///
//////表///
{
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
///
/////////
{
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
///
//////表列///
{
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