示例#1
0
        private void addVehicle()
        {
            getOwnerDetails(out string ownerPhone, out string ownerName);
            Console.WriteLine("Please choose the vehicle type out of the following options");
            displayEnumOptions <VehicleBuilder.eVehicleType>();
            VehicleBuilder.eVehicleType userRequestedVehicleType =
                (VehicleBuilder.eVehicleType)getEnumChoiceFromUser <VehicleBuilder.eVehicleType>();
            Dictionary <string, VehicleParam> paramsDictionary = new Dictionary <string, VehicleParam>();
            Vehicle             vehicleToAdd   = VehicleBuilder.BuildVehicle(userRequestedVehicleType);
            List <VehicleParam> parametersList = vehicleToAdd.GetNewVehicleParams();

            foreach (VehicleParam param in parametersList)
            {
                Console.WriteLine("Please enter {0}", param.FriendlyName);
                if (param.Type.IsEnum)
                {
                    Console.WriteLine("Options: " + string.Join(",", Enum.GetNames(param.Type)));
                    string userInput = Console.ReadLine();
                    param.Value = Enum.Parse(param.Type, userInput);
                }
                else
                {
                    string userInput = Console.ReadLine();
                    param.Value = Convert.ChangeType(userInput, param.Type);
                }

                paramsDictionary.Add(param.Name, param);
            }

            vehicleToAdd.InitNewVehicle(paramsDictionary);
            m_Garage.AddVehicle(ownerPhone, ownerName, vehicleToAdd);
            Console.WriteLine("Vehicle was added to the garage");
        }