/// <summary>
        /// 给对象赋值的方法(不赋地址)(同一个类型),含过滤
        /// </summary>
        /// <typeparam name="T"><peparam>
        /// <param name="left">=号左边</param>
        /// <param name="right">=号右边</param>
        /// <param name="id">过滤条件</param>
        public static void Assignment<T>(T left, T right, string id=null)
        {
            Type type = left.GetType();
            List<PropertyInfo> pList = type.GetProperties().ToList();
            for (int i = 0; i < pList.Count; i++)
            {
                //根据属性名获得指定的属性对象
                PropertyInfo gc = type.GetProperty(pList[i].Name);
                //设置属性的值
                if (id != null) 
                {
                    if (pList[i].Name != id) 
                    {
                        gc.SetValue(left, pList[i].GetValue(right, null), null);
                    }
                }
                else 
                {
                    gc.SetValue(left, pList[i].GetValue(right, null), null);
                }
               
            }
        }
View Code

相关文章:

  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-05
  • 2021-11-12
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案