Type ty = t.GetType();
PropertyInfo[] PropertyInfo = ty.GetProperties();
string Typename = typeof(T).Name;
PropertyInfo
[1].GetValue(????)

GetValue有两个参数一个返回值,参数一就是要获取属性值的对象,PropertyInfo只是表示属性元数据,跟对象无关,因此你要获取谁的属性得指定
参数二是指定索引值的,PropertyInfo不光是针对属性还有索引器,二者都是用PropertyInfo描述的,因此如果是针对索引器的,那么参数二就是索引参数,否则为null

补充:静态和引用属性不一样 静态第一个要传Null
转自知乎

相关文章:

  • 2021-10-16
  • 2021-04-03
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-12-31
  • 2022-12-23
  • 2021-08-27
  • 2021-06-20
相关资源
相似解决方案