当前位置: 代码迷 >> ASP.NET >> 请问以上VS2008代码是什么意思?帮忙详细注释说明
  详细解决方案

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

热度:3436   发布时间:2013-02-25 00:00:00.0
请教以下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、表名。
  相关解决方案