//Loop through all the properties public static void AddValuesToMovementsViewModel(object movement, ref MovementsViewModel movementsViewModel) { foreach (var property in movementsViewModel.GetType().GetProperties()) { var propertyValue = GetPropertyValue(movement, property.Name); if (propertyValue != null) { var properties = GetPropertiesNamesFromObject(movementsViewModel); if (properties.Contains(property.Name)) { movementsViewModel.GetType().GetProperty(property.Name)?.SetValue(movementsViewModel, propertyValue); } } } }
//Loop through all the properties private static void AddValueToMovementsModel(object movement, ref MovementsViewModel movementsViewModel) { foreach (var property in movementsViewModel.GetType().GetProperties()) { var propertyValue = GetPropertyValue(movement, property.Name); if (propertyValue != null) { SetPropertyValueToMovementsViewModel(property.Name, propertyValue, ref movementsViewModel); } } }
public static bool SetPropertyValueToMovementsViewModel(string propertyName, object propertyValue, ref MovementsViewModel modelToUpdate) { try { var properties = GetPropertiesNamesFromObject(modelToUpdate); if (properties.Contains(propertyName)) { modelToUpdate.GetType().GetProperty(propertyName).SetValue(modelToUpdate, propertyValue); return(true); } return(false); } catch { return(false); } }