private void SetPropertyValue(object targetEntity, object sourceValue, Type sourceType, IPropertyMapping mapping, bool throwOnError) { try { object targetValue = sourceValue; if (mapping.HasConversion) { targetValue = mapping.Convert(sourceValue); } else if (mapping.PropertyInfo.PropertyType != sourceType && !IsNullable(mapping.PropertyInfo.PropertyType)) { //if the types differ, change them - unless the target is nullable, //as the Convert will fail but the SetValue succeeds: targetValue = System.Convert.ChangeType(sourceValue, mapping.PropertyInfo.PropertyType); } mapping.PropertyInfo.SetValue(targetEntity, targetValue, null); } catch (Exception ex) { Log.Error("{0}: Error setting property value, {1}, {2}", this.GetType().Name, mapping.PropertyInfo.Name, ex.Message); if (throwOnError) { throw; } } }