首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

反射取值有关问题,求指点

2012-02-26 
反射取值问题,求指点//当获取的属性的类型是一个类时,就会报出“为将对象引用设置到对象的实例”的异常下面

反射取值问题,求指点
//当获取的属性的类型是一个类时,就会报出“为将对象引用设置到对象的实例”的异常
下面是伪代码

C# code
   public class A    {        public int Id { get; set; }        B model = new B();        public B Model        {            get { return model; }            set { model = value; }        }    }    public class B    {        public int Id { get; set; }    }    public void Reflection()    {        A a = new A();        PropertyInfo[] Arr = a.GetType().GetProperties();        Dictionary<string, object> dic = new Dictionary<string, object>();        foreach (PropertyInfo item in Arr)        {            //当获取的属性的类型是一个类时,就会报出“为将对象引用设置到对象的实例”的异常            dic.Add(item.Name,item.GetValue(a,null));        }    }


[解决办法]
你现在的代码没问题
[解决办法]
探讨
自己搞定了。

热点排行