Type t = typeof(B_InventoryRecord); var properties = t.GetProperties(); var p = list[0]; foreach (var item in properties) { string value = (string)t.GetProperty(item.Name).GetValue(p, null); res.Add(value); }
这里有一些缺点。
缺点一:有些类的值不需要赋值,或者和数据库的字段不对应。这个可以使用Attribute标签加一些限制
缺点二:GetValue()方法获取的值都是object类型