From f95b737c0be9080bb004613fd75ec94c16a0219b Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Tue, 19 Jan 2016 17:04:33 +0100 Subject: [PATCH] more readable implementation of VehicleContainer.AddComponent --- .../Simulation/Impl/VehicleContainer.cs | 55 ++++--------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs index 01e101d880..269795aa20 100644 --- a/VectoCore/Models/Simulation/Impl/VehicleContainer.cs +++ b/VectoCore/Models/Simulation/Impl/VehicleContainer.cs @@ -170,53 +170,18 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl { Components.Add(component); - var engine = component as IEngineInfo; - if (engine != null) { - Engine = engine; - } - - var driver = component as IDriverInfo; - if (driver != null) { - Driver = driver; - } - - var gearbox = component as IGearboxInfo; - if (gearbox != null) { - Gearbox = gearbox; - } - - var vehicle = component as IVehicleInfo; - if (vehicle != null) { - Vehicle = vehicle; - } - - var cycle = component as ISimulationOutPort; - if (cycle != null) { - Cycle = cycle; - } - - var milage = component as IMileageCounter; - if (milage != null) { - MilageCounter = milage; - } - - var breaks = component as IBrakes; - if (breaks != null) { - Brakes = breaks; - } - - var road = component as IRoadLookAhead; - if (road != null) { - Road = road; - } - - var clutch = component as IClutchInfo; - if (clutch != null) { - Clutch = clutch; - } + component.Switch() + .If<IEngineInfo>(c => Engine = c) + .If<IDriverInfo>(c => Driver = c) + .If<IGearboxInfo>(c => Gearbox = c) + .If<IVehicleInfo>(c => Vehicle = c) + .If<ISimulationOutPort>(c => Cycle = c) + .If<IMileageCounter>(c => MilageCounter = c) + .If<IBrakes>(c => Brakes = c) + .If<IRoadLookAhead>(c => Road = c) + .If<IClutchInfo>(c => Clutch = c); } - public void CommitSimulationStep(Second time, Second simulationInterval) { Log.Info("VehicleContainer committing simulation. time: {0}, dist: {1}, speed: {2}", time, Distance, VehicleSpeed); -- GitLab