Example #1
0
        public static void Main()
        {
            var kutyaToDtoMapping = new MappingBuilder <Kutya, KutyaDto>()
                                    .MapMatchingPropertyChains()
                                    .MapProperty(k => k.DtoProperty, kk => kk.EntityProperty)
                                    .IgnoreProperty(k => k.Ignored)
                                    .Build();

            try
            {
            }
            catch
            {
            }
            finally { Console.WriteLine(); }
            var kutyak = new[] {
                new Kutya
                {
                    Id             = 1, Name = "Bodri",
                    EntityProperty = 5,
                    Ignored        = "IGNORE!"
                }, new Kutya {
                },
                new Kutya {
                    Id = 3, Name = "Pimpedli", EntityProperty = 10
                }
            };
            var dtok = kutyak.AsQueryable().Select(kutyaToDtoMapping.ToExpression()).ToList();
        }
 public static MappingBuilder <TSource, TTarget> IgnoreProperty <TSource, TTarget, TProperty>(this MappingBuilder <TSource, TTarget> builder, Expression <Func <TTarget, TProperty> > propertySelector)
 => builder.Add(new IgnorePropertyMapping <TSource, TTarget>(builder.SourceParameter, (propertySelector.Body as MemberExpression).Member));
 public static MappingBuilder <TSource, TTarget> MapMatchingPropertyChains <TSource, TTarget>(this MappingBuilder <TSource, TTarget> builder)
 => builder.Do(b => typeof(TTarget).GetProperties().For(p => typeof(TSource).GetPropertyChains(p.Name).FirstOrDefault()?.Branch(ch => ch != null, ch => builder.Add(new PropertyChainMapping <TSource, TTarget>(builder.SourceParameter, p, ch)))));
 public static MappingBuilder <TSource, TTarget> MapProperty <TSource, TTarget, TProperty>(this MappingBuilder <TSource, TTarget> builder, Expression <Func <TTarget, TProperty> > propertySelector, Expression <Func <TSource, TProperty> > mappingExpression)
 => builder.Add(new CustomMemberMapping <TSource, TTarget, TProperty>(builder.SourceParameter, propertySelector, mappingExpression));