public KeyValuePair <string, string> Stringify(TSourceEntity source, TTargetEntity target) { Apply(source, target); var targetFieldString = stringify(targetFieldFunc(target)); var simplePropertyNameAggregator = new SimplePropertyNameAggregator(); simplePropertyNameAggregator.Visit(targetField.Body, false); if (string.IsNullOrEmpty(tagVlaue)) { var error = $"Can't stringify a field where tag value is not defined for source entity: {typeof(TSourceEntity).Name}, " + $"target entity: {typeof(TTargetEntity).Name}"; throw new Exception(error); } var keyFormat = tagVlaue + ".{0}"; var result = new KeyValuePair <string, string>( string.Format(keyFormat, simplePropertyNameAggregator.PropertyMetaData.PropertyInfoList[0].Name), targetFieldString); return(result); }
public TTargetEntity Convert(TSourceEntity sourceEntity) { var targetEntity = new TTargetEntity(); foreach (var fieldMapper in fieldMappers) { fieldMapper.Apply(sourceEntity, targetEntity); } return(targetEntity); }
public Dictionary <string, string> Stringify(TSourceEntity sourceEntity) { var targetEntity = new TTargetEntity(); var result = new Dictionary <string, string>(); foreach (var fieldMapper in fieldMappers) { var pair = fieldMapper.Stringify(sourceEntity, targetEntity); result.Add(pair.Key, pair.Value); } return(result); }
public void Apply(TSourceEntity source, TTargetEntity target) { var sourceValue = sourceFieldGetter(source); targetFieldSetter(target, sourceValue); }