C#源代码生成器
? SdtcnCoder參考了TheBeerHouse的系統結構,采用了三層結構和緩存技術,這里對SdtcnCoder代碼生成進行簡單介紹.
一、數據類型模型?
1、??Field類是字段類型的基類,對SqlServer2005數據列屬性進行了映射;?
2、??BigInt、Binary等是具體類,如下Binary,主要重寫各種數據類型在C#語法中的類型、默認值、字符類型時的長度等;?
using System;?
using System.Data;?
using System.Collections.Generic;?
using System.Text;?
-?
namespace Sdtcn.Coder?
{?
? ? public class Binary : Field?
? ? {?
? ?? ???///??
? ?? ???/// 構造函數?
? ?? ???///??
? ?? ???///??
? ?? ?? ?public Binary (DataRow row) : base(row)?
? ?? ???{?
? ?? ?? ?? ??
? ?? ???}?
? ?? ???///??
? ?? ???/// 重寫返回C#類型的方法?
? ?? ???///??
? ?? ???public override string CSharpTypeName?
? ?? ???{?
? ?? ?? ?? ?get?
? ?? ?? ?? ?{?
? ?? ?? ?? ?? ? return "Byte[]";?
? ?? ?? ?? ?}?
? ?? ???}?
? ?? ???///??
? ?? ???/// 重寫返回值?
? ?? ???///??
? ?? ???public override string DefaultValue?
? ?? ???{?
? ?? ?? ?? ?get?
? ?? ?? ?? ?{?
? ?? ?? ?? ?? ? return "null";?
? ?? ?? ?? ?}?
? ?? ???}?
? ?? ???public override string Length?
? ?? ???{?
? ?? ?? ?? ?get?
? ?? ?? ?? ?{?
? ?? ?? ?? ?? ? return "(" + this.Max_Length.ToString() + ")";?
? ?? ?? ?? ?}?
? ?? ???}?
? ? }?
}?
二、代碼生成?
代碼生成主要由Table類負責,主要方法分為生成存儲過程、生成DAL、生成BLL、生成Aspx(當前還沒有實現,方法和生成BLL雷同)等幾類,具體參見源代碼。?
?
轉載于:https://blog.51cto.com/bbsitsq/1182351
總結
- 上一篇: getch, getche, getch
- 下一篇: 把C#.NET程序移植到DB2上的经验浅