예제 #1
0
        private void LoadProductsToCatalog(Product[] cars)
        {
            foreach (Product car in cars)
            {
                switch (car.Brand)
                {
                case "Bmw":
                    BmwBuilder bmwBuilder = new BmwBuilder();
                    Product    bmw        = bmwBuilder.Create();
                    FillFieldsWithCarAttrs(bmw, car);
                    products.Add(bmw);
                    break;

                case "Lada":
                    LadaBuilder ladaBuilder = new LadaBuilder();
                    Product     lada        = ladaBuilder.Create();
                    FillFieldsWithCarAttrs(lada, car);
                    products.Add(lada);
                    break;

                case "Pegueot":
                    PegueotBuilder pegueotBuilder = new PegueotBuilder();
                    Product        pegueot        = pegueotBuilder.Create();
                    FillFieldsWithCarAttrs(pegueot, car);
                    products.Add(pegueot);
                    break;
                }
            }
        }
예제 #2
0
        public Storage(string path)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Auto
            };

            Product[] cars = JsonConvert.DeserializeObject <Product[]>(File.ReadAllText(path), settings);
            products = new List <Product>();
            foreach (Product car in cars)
            {
                switch (car.Brand)
                {
                case "Bmw":
                    BmwBuilder bmwBuilder = new BmwBuilder();
                    Product    bmw        = bmwBuilder.Create();
                    FillFieldsWithCarAttrs(bmw, car);
                    products.Add(bmw);
                    break;

                case "Lada":
                    LadaBuilder ladaBuilder = new LadaBuilder();
                    Product     lada        = ladaBuilder.Create();
                    FillFieldsWithCarAttrs(lada, car);
                    products.Add(lada);
                    break;

                case "Pegueot":
                    PegueotBuilder pegueotBuilder = new PegueotBuilder();
                    Product        pegueot        = pegueotBuilder.Create();
                    FillFieldsWithCarAttrs(pegueot, car);
                    products.Add(pegueot);
                    break;
                }
            }
        }