static void Main(string[] args)
        {
            Mapper.Initialize(cfg =>
            {
                //cfg.AddProfile<MyProfile>();

                //Scan all program profiles
                cfg.AddProfiles(typeof(Program));
            });

            //Automapper 8 and beyond
            //var configuration = new MapperConfiguration(cfg => {
            //     //cfg.CreateMap<SourceOrder, DestinationOrder>();
            //     cfg.AddProfile<MyProfile>();
            // });
            //IMapper iMapper = configuration.CreateMapper();

            var src = new SourceOrder()
            {
                Created = DateTime.Now.ToLongDateString(), OrderId = Guid.NewGuid().ToString()
            };
            //var dest = iMapper.Map<DestinationOrder>(src);
            var dest = Mapper.Map <DestinationOrder>(src, opt => opt.Items.Add("IsPayByCard", false));
            //var dest = Mapper.Map<DestinationOrder>(src, opt=>opt.Items.Add("IsPayByCard",true));
            var another = Mapper.Map(new SourceDelivery()
            {
                Company = "company", Cost = 2.0m
            }, dest);

            List <FlatDestination> destinations = Mapper.Map <List <FlatDestination> >(src);
        }
            public List <FlatDestination> Convert(SourceOrder source, List <FlatDestination> destination, ResolutionContext context)
            {
                var result = new List <FlatDestination>(source.Items.Count);

                source.Items.ForEach(i =>
                {
                    var item     = context.Mapper.Map <FlatDestination>(i);
                    item.OrderId = source.OrderId;
                    result.Add(item);
                });
                return(result);
            }
        //Old way before automapper 8.0
        private static void Init()
        {

           // Automapper 8 and beyond
            var configuration = new MapperConfiguration(cfg =>
            {
                //cfg.CreateMap<SourceOrder, DestinationOrder>();
                //cfg.AddProfile<MyProfile>();
                //var profiles = typeof(MyProfile).Assembly.GetTypes().Where(x => typeof(Profile).IsAssignableFrom(x)).ToList();
                //cfg.AddProfiles();
                //cfg.AddMaps(Assembly.GetExecutingAssembly());
                cfg.AddMaps(typeof(MyProfile).Assembly);
            });

            IMapper iMapper = configuration.CreateMapper();

            var src = SourceOrder.SeedData();
            Console.WriteLine(JValue.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(src)).ToString(Formatting.Indented));

            var dest = iMapper.Map<DestinationOrder>(src, opt => opt.Items.Add("IsPayByCard", false));
            //var dest = iMapper.Map<DestinationOrder>(src, opt=>opt.Items.Add("IsPayByCard",true));


            Console.WriteLine(JValue.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(dest)).ToString(Formatting.Indented));
           
            dest = iMapper.Map(new SourceDelivery()
            {
                Company = "company",
                Cost = 2.0m
            }, dest);

            var srcDelivery = new SourceDelivery()
            {
                Company = "company",
                Cost = 2.0m
            };
            var another = iMapper.Map<DestinationDelivery>(srcDelivery);

            List<FlatDestination> destinations = iMapper.Map<List<FlatDestination>>(src);

            Console.WriteLine(JValue.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(destinations)).ToString(Formatting.Indented));
        }