internal Vehicle CreateVehicle(string csvString) { var vehTypes = LoadTypes("types.csv"); string[] fields = csvString.Split(';'); int id = int.Parse(fields[0]); VehicleType vehType = null; foreach (var type in vehTypes) { if (int.Parse(fields[1]) == type.IdType) { vehType = type; break; } } string modelName = fields[2]; string modelNumber = fields[3]; int carWeight = int.Parse(fields[4]); int manufactureYear = int.Parse(fields[5]); int carMileage = int.Parse(fields[6]); Color carColor = (Color)Enum.Parse(typeof(Color), fields[7]); double carTankCapacity = double.Parse(fields[11]); AbstractEngine engine = null; switch (fields[8]) { case "Gasoline": engine = new GasolineEngine(double.Parse(fields[9]), double.Parse(fields[10])); break; case "Diesel": engine = new DieselEngine(double.Parse(fields[9]), double.Parse(fields[10])); break; case "Electrical": engine = new ElectricalEngine(double.Parse(fields[10])); break; } return(new Vehicle(id, vehType, engine, modelName, modelNumber, carWeight, manufactureYear, carMileage, carColor, carTankCapacity)); }
public Vehicle CreateVehicle(string csvString) { string[] s = csvString.Split(","); List <VehicleType> localTypes = LoadTypes(@"types.csv"); AbstractEngine localEngine = null; Vehicle.Colour localColour = (Vehicle.Colour)Enum.Parse(typeof(Vehicle.Colour), s[7]); if (s[8] == "Electrical") { localEngine = new ElectricalEngine(int.Parse(s[9])); } else if (s[8] == "Gasoline") { localEngine = new GasolineEngine(double.Parse(s[10], System.Globalization.CultureInfo.InvariantCulture), double.Parse(s[9], System.Globalization.CultureInfo.InvariantCulture)); } else if (s[8] == "Diesel") { localEngine = new DieselEngine(double.Parse(s[10], System.Globalization.CultureInfo.InvariantCulture), double.Parse(s[9], System.Globalization.CultureInfo.InvariantCulture)); } return(new Vehicle(int.Parse(s[0]), localTypes[int.Parse(s[1]) - 1], localEngine, s[2], s[3], int.Parse(s[4]), int.Parse(s[5]), int.Parse(s[6]), localColour, int.Parse(s[11]), new List <Rent>())); }
private static AbstractEngine GetEngineByString(string engineString) { AbstractEngine engine = null; string[] engineStringPieces = engineString.Split(' ', StringSplitOptions.RemoveEmptyEntries); var engineType = Enum.Parse <EngineTypes>(engineStringPieces[0]); switch (engineType) { case EngineTypes.Gasoline: engine = new GasolineEngine ( double.Parse(engineStringPieces[1]), double.Parse(engineStringPieces[2]) ); break; case EngineTypes.Diesel: engine = new DieselEngine ( double.Parse(engineStringPieces[1]), double.Parse(engineStringPieces[2]) ); break; case EngineTypes.Electrical: engine = new ElectricalEngine ( double.Parse(engineStringPieces[1]) ); break; default: break; } return(engine); }