当前位置: 代码迷 >> C# >> 通过反射给属性赋值报错,该怎么处理
  详细解决方案

通过反射给属性赋值报错,该怎么处理

热度:29   发布时间:2016-05-05 04:53:08.0
通过反射给属性赋值报错
Web应用程序:
第一次写,照搬winform程序。
应该都可以用吧,为什么下忙会报错哪?
 PropertyInfo[] pSrc = typeof(ApplicationClass).GetProperties();
            PropertyInfo[] pDest = this.GetType().GetProperties();
            foreach (PropertyInfo property in pSrc)
            {
                IList<PropertyInfo> p = pDest.Where(r => r.Name == property.Name).ToList();
                if (p.Count == 1)
                {
                    //p[0].SetValue(this, property.GetValue(applyClass, null), null);
                    object v = property.GetValue(applyClass, null);
                    p[0].SetValue(this,v,null);
                }
            }



------解决思路----------------------


有的属性只有get 没有set 所有报错了。
  相关解决方案