Exemple #1
0
            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);
            }
Exemple #2
0
            public TTargetEntity Convert(TSourceEntity sourceEntity)
            {
                var targetEntity = new TTargetEntity();

                foreach (var fieldMapper in fieldMappers)
                {
                    fieldMapper.Apply(sourceEntity, targetEntity);
                }

                return(targetEntity);
            }
Exemple #3
0
            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);
            }
Exemple #4
0
            public void Apply(TSourceEntity source, TTargetEntity target)
            {
                var sourceValue = sourceFieldGetter(source);

                targetFieldSetter(target, sourceValue);
            }