Reflection Help - Set properties on object based on another object

前端 未结 1 1378
悲&欢浪女
悲&欢浪女 2021-01-24 03:35

I could use a bit of relection help. I am passing an object into the constructor of another object. I need to loop through the parameter\'s properties and set the new objects pr

相关标签:
1条回答
  • 2021-01-24 04:32

    Something like this I think

    Type target = typeof(DisabilityPaymentAddEntity);
    foreach(PropertyInfo pi in display.GetType().GetProperties())
    {
         PropertyInfo targetProp = target.GetProperty(pi.Name);
         if(targetProp!=null)
         {
            targetProp.SetValue(this, pi.GetValue(display, null), null);
         }
    }
    
    0 讨论(0)
提交回复
热议问题