C#/.NET遍历类取值

项目是WebApi的,.Net Framework 4.5,写的接口。

因为项目需要,有个类大概有几十个字段需要进行判断,

一开始想用

System.Reflection.PropertyInfo

但是,不知道为什么一旦引用了这个,就会报500(Internal Server Error)这个错误。

后来偶然发现有别的方法

var a = applySubmitEntity.applyData.GetType().GetProperty("companyName").GetValue(applySubmitEntity.applyData,null);

完美解决。

posted on 2020-12-15 18:03  奥奥没有利  阅读(132)  评论(0)    收藏  举报