?? buildermodel.cs
字號:
namespace LTP.BuilderModel
{
using LTP.CodeHelper;
using LTP.IBuilder;
using LTP.Utility;
using System;
using System.Collections.Generic;
public class BuilderModel : IBuilderModel
{
protected List<ColumnInfo> _fieldlist;
protected string _modelname = "";
protected string _modelpath = "";
protected string _namespace = "Maticsoft";
public string CreatModel()
{
StringPlus plus = new StringPlus();
plus.AppendLine("using System;");
plus.AppendLine("namespace " + this.Modelpath);
plus.AppendLine("{");
plus.AppendSpaceLine(1, "/// <summary>");
plus.AppendSpaceLine(1, "/// 實體類" + this._modelname + " 。(屬性說明自動提取數據庫字段的描述信息)");
plus.AppendSpaceLine(1, "/// </summary>");
plus.AppendSpaceLine(1, "public class " + this._modelname);
plus.AppendSpaceLine(1, "{");
plus.AppendSpaceLine(2, "public " + this._modelname + "()");
plus.AppendSpaceLine(2, "{}");
plus.AppendLine(this.CreatModelMethod());
plus.AppendSpaceLine(1, "}");
plus.AppendLine("}");
plus.AppendLine("");
return plus.ToString();
}
public string CreatModelMethod()
{
StringPlus plus = new StringPlus();
StringPlus plus2 = new StringPlus();
StringPlus plus3 = new StringPlus();
plus.AppendSpaceLine(2, "#region Model");
foreach (ColumnInfo info in this.Fieldlist)
{
string columnName = info.ColumnName;
string typeName = info.TypeName;
bool isIdentity = info.IsIdentity;
bool isPK = info.IsPK;
bool cisNull = info.cisNull;
string deText = info.DeText;
typeName = CodeCommon.DbTypeToCS(typeName);
string str4 = "";
if ((CodeCommon.isValueType(typeName) && !isIdentity) && (!isPK && cisNull))
{
str4 = "?";
}
plus2.AppendSpaceLine(2, "private " + typeName + str4 + " _" + columnName.ToLower() + ";");
plus3.AppendSpaceLine(2, "/// <summary>");
plus3.AppendSpaceLine(2, "/// " + deText);
plus3.AppendSpaceLine(2, "/// </summary>");
plus3.AppendSpaceLine(2, "public " + typeName + str4 + " " + columnName);
plus3.AppendSpaceLine(2, "{");
plus3.AppendSpaceLine(3, "set{ _" + columnName.ToLower() + "=value;}");
plus3.AppendSpaceLine(3, "get{return _" + columnName.ToLower() + ";}");
plus3.AppendSpaceLine(2, "}");
}
plus.Append(plus2.Value);
plus.Append(plus3.Value);
plus.AppendSpaceLine(2, "#endregion Model");
return plus.ToString();
}
public List<ColumnInfo> Fieldlist
{
get
{
return this._fieldlist;
}
set
{
this._fieldlist = value;
}
}
public string ModelName
{
get
{
return this._modelname;
}
set
{
this._modelname = value;
}
}
public string Modelpath
{
get
{
return this._modelpath;
}
set
{
this._modelpath = value;
}
}
public string NameSpace
{
get
{
return this._namespace;
}
set
{
this._namespace = value;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -