62,046
社区成员
发帖
与我相关
我的任务
分享
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; }
}
}