public void InsertarParte(IParteAuto parte) { if (NoCumpleRestricciones(parte)) { throw new Exception("Esa parte esta restringida a una unica"); } _partesAuto.Add(parte); }
private bool NoCumpleRestricciones(IParteAuto parte) { var esTanqueCombustible = parte.GetType() == typeof(TanqueCombustible); var esMotor = parte.GetType() == typeof(Motor); var existeTanqueCombustible = _partesAuto.Any(x => x.GetType() == typeof(Motor) && esMotor); var existeMotor = _partesAuto.Any(x => x.GetType() == typeof(Motor) && esMotor); return(existeMotor || existeTanqueCombustible); }