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);
完美解决。
浙公网安备 33010602011771号