運行類:
Code
class Program
{
static void Main(string[] args)
{
UserInfo userInfo = new UserInfo();
Type type = userInfo.GetType();
TableAttribute ta = (TableAttribute)type.GetCustomAttributes(false)[0];
Console.WriteLine("數據表名:" + ta.TableName);
PropertyInfo[] infos = type.GetPropertIEs();
foreach (PropertyInfo info in infos)
{
object[] attributes = info.GetCustomAttributes(false);
foreach (object att in attributes)
{
if (att is ColumnAttribute)
{
ColumnAttribute ca = att as ColumnAttribute;
string cn = ca.ColumnName == null ? info.Name : ca.ColumnName;
Console.WriteLine("字段名:" + cn);
Console.WriteLine("字段類型:" + ca.DbType);
}
}
}
}
下面是運行結果的截圖: