public Aviary ToAviary(AviaryDTO aviaryDTO) { try { if (aviaryDTO == null) { throw new ArgumentException("Пустой DTO объект (вольер)!!!"); } Aviary aviary = null; IAviaryConverter converter; switch (aviaryDTO.GetType().Name.ToString()) { case "AquariumDTO": converter = new AquariumConverter(); aviary = converter.ToAviary(aviaryDTO); break; case "CageDTO": converter = new CageConverter(); aviary = converter.ToAviary(aviaryDTO); break; case "GlassAviaryDTO": converter = new GlassAviaryConverter(); aviary = converter.ToAviary(aviaryDTO); break; case "PoolDTO": converter = new PoolConverter(); aviary = converter.ToAviary(aviaryDTO); break; case "YardDTO": converter = new YardConverter(); aviary = converter.ToAviary(aviaryDTO); break; } return(aviary); } catch (ArgumentException) { throw; } }
public Aviary ToAviary(AviaryDTO aviaryDTO) { try { if (aviaryDTO == null || !(aviaryDTO is GlassAviaryDTO)) { throw new ArgumentException("Пустой DTO объект (вольер) или не подходящего типа!!!"); } var aviary = new GlassAviary((aviaryDTO as GlassAviaryDTO).Kind, (aviaryDTO as GlassAviaryDTO).Volume, aviaryDTO.Capacity); var converter = new AnimalConverter(); foreach (var inhabitant in aviaryDTO.Inhabitants) { aviary.SettleAnimal(converter.ToAnimal(inhabitant)); } return(aviary); } catch (ArgumentException) { throw; } }