日期:2014-05-17  浏览次数:20426 次

请教以下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、表名。