当前位置: 代码迷 >> ASP.NET >> 反射取值有关问题,求指点
  详细解决方案

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

热度:7430   发布时间:2013-02-25 00:00:00.0
反射取值问题,求指点
//当获取的属性的类型是一个类时,就会报出“为将对象引用设置到对象的实例”的异常
下面是伪代码
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));        }    }


------解决方案--------------------------------------------------------
你现在的代码没问题
------解决方案--------------------------------------------------------
探讨
自己搞定了。
  相关解决方案