首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问以上VS2008代码是什么意思?帮忙详细注释说明

2012-11-07 
请教以下VS2008代码是什么意思?帮忙详细注释说明public abstract class BaseDALTEntity where TEntity :

请教以下VS2008代码是什么意思?帮忙详细注释说明
public abstract class BaseDAL<TEntity> where TEntity : new()
  {
  public BaseDAL()
  {
  Type t = typeof(TEntity);
  List<string> primaryKeys = new List<string>();
  PropertyInfo[] properties = t.GetProperties();
  foreach (PropertyInfo p in properties)
  {
  if (p.GetCustomAttributes(typeof(PrimaryKeyAttribute), false).Length > 0)
  {
  primaryKeys.Add(p.Name);
  }
  if (p.GetCustomAttributes(typeof(IdentityFieldAttribute), false).Length > 0)
  {
  IdentityField = p.Name;
  }
  }
  PrimaryKey = primaryKeys.ToArray();
  Object[] tableNameAttributes = t.GetCustomAttributes(typeof(TableNameAttribute), false);
  if (tableNameAttributes.Length > 0)
  {
  TableName = ((TableNameAttribute)tableNameAttributes[0]).TableName;
  }
  else
  {
  TableName = t.Name;
  }

  }

[解决办法]
用反射为实体类初始化,根据实体类的特性设置主键、id、表名。

热点排行