Fill similar objects property by reflection

foreach (PropertyInfo SourceProp in SourcePO.GetType().GetProperties())           {               if (SourceProp != null)               {                   PropertyInfo TargetProp = TargetPO.GetType().GetProperty(SourceProp.Name.ToUpper());                   if (TargetProp != null && TargetProp.CanWrite)                   {                       object SourcePropValue = SourceProp.GetValue(SourcePO, null);                       TargetProp.SetValue(TargetPO, SourcePropValue, null);                   }               }           }

Create a website or blog at WordPress.com

Up ↑