我从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;到时候会传进来各种实体类,我不知道是那个实体(就是我不知道Base.UI.Model.Order是这个类型的有可能是别的类型的),但是我要求出所有的值!
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;到时候会传进来各种实体类,我不知道是那个实体(就是我不知道Base.UI.Model.Order是这个类型的有可能是别的类型的),但是我要求出所有的值!
解决方案 »
- 求助!!使用服务器控件fileupload控件.如何判断是否上传成功或着完成..
- 在C#后台给前台DIV赋值
- 出现缓存不可用的错误。怎么解决?
- 日语对asp.net 重要吗?与英语比较
- 弹出窗口的问题
- 能否用select语句查询在dataset中的表的记录?
- 新手求助
- 求助:在winxp sp1中无法安装ASP.NET!
- 一个关于asp.net中连接数据库的问题
- 急!我的自定义服务器控件上有个按扭,当我把这自定义服务器控件放在页面最前端,下面还有一TextBox(AutoPostBack=true),我在TextBox回车
- mssql怎么查看最新更新的数据表?
- 【如何在Iframe中导出xml文件,求解。弹出保存对话框,而不是直接显示在页面上】
对object要有要求,如需要实现某个interface或继承某个类,
....
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; }
}
}