有些属性需要参数,有些只写,要过滤掉:
PropertyInfo[] entityProperties = entityType
  .GetProperties()
  .Where(p => p.CanRead && p.GetIndexParameters().Length == 0)
  .ToArray();

解决方案 »

  1.   

    GetValue的第二个参数是索引化属性的可选索引值。 对于非索引化属性,才为null,如果是索引化属性,就不能是null
      

  2.   

    entityValues[i] = entityProperties[i].GetValue(entity, null);    参数计数不匹配。 你确定所有的属性都是非索引属性?
      

  3.   

    若要使用 GetValue 方法,请先获取类 Type。 从 Type 获取 PropertyInfo。 从 PropertyInfo 使用 GetValue 方法。 
    参考
    http://msdn.microsoft.com/zh-cn/library/b05d59ty.aspx
    demo:
    http://www.cnblogs.com/dyfzwj/archive/2011/04/16/2017916.html
    public DataTable FillDataTable(List<T> modelList)
            {
                if (modelList == null || modelList.Count == 0)
                {
                    return null;
                }
                DataTable dt = CreateData(modelList[0]);            foreach(T model in modelList)
                {
                    DataRow dataRow = dt.NewRow();
                    foreach (PropertyInfo propertyInfo in typeof(T).GetProperties())
                    {
                        dataRow[propertyInfo.Name] = propertyInfo.GetValue(model, null);
                    }
                    dt.Rows.Add(dataRow);
                }
                return dt;
            }