コード例 #1
0
ファイル: Program.cs プロジェクト: kerkoag/MutatorFX
        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();
        }
コード例 #2
0
 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));
コード例 #3
0
 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)))));
コード例 #4
0
 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));