object转换成List类型或实体类
我从Dictionary 里面拿到 一个object的实体类,但是我不知道是什么实体类,我想取得这个实体类里面的所有字段的值,
应该怎么弄啊!
Dictionary<string, object> dic = new Dictionary<string, object>(); Base.UI.Model.Order or = new Base.UI.Model.Order(); or.AD_ID = 100; or.Buy_nick = "test"; dic["test"] = or;
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Reflection;namespace TestThree{ public class Program { /// <summary> /// 测试方法 /// </summary> /// <param name="args"></param> static void Main(string[] args) { IDictionary<string, object> testDict = new Dictionary<string, object>(); testDict.Add("测试", new Student()); object objYouGet = testDict["测试"]; Type t = objYouGet.GetType(); PropertyInfo[] proInfos = t.GetProperties(); foreach (PropertyInfo item in proInfos) { Console.WriteLine("字段名称:{0}", item.Name); Console.WriteLine("字段值:{0}", item.GetValue(objYouGet, null)); Console.WriteLine("字段类型:{0}", item.PropertyType); Console.WriteLine("--------------------"); } Console.ReadLine(); } } /// <summary> /// 测试类 /// </summary> public class Student { public Student() { this.Id = 0; this.ChineseName = "测试中文名"; this.EnglishName = "Test EnglishName"; this.Score = 100; } public int Id { get; set; } public string ChineseName { get; set; } public string EnglishName { get; set; } public double Score { get; set; } }}