c#通过属性的名字获取值

来源:互联网 发布:淘宝ps4游戏商店 编辑:程序博客网 时间:2024/05/02 01:19

本文章持续更新一小段时间,作为日常工作的总结吧

SuperStudent superStudent = new SuperStudent();            superStudent.s = new Student();            superStudent.s.SAge = 10;            Type t = superStudent.GetType();            FieldInfo[] fileInfos = t.GetFields(BindingFlags.Public | BindingFlags.Instance);            Student student = t.GetField("s").GetValue(superStudent) as Student;            Type t1 = t.GetField("t").GetType();

这个superStudent和Student是父子关系,随便替换一个类就好了,这里只是一个方法而已,因为网上代码有错误,所以给个能用的出来。

0 0
原创粉丝点击