public string AddAstronaut(string type, string astronautName) { IAstronaut astronaut = null; switch (type) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } astronautRepository.Add(astronaut); return(string.Format(OutputMessages.AstronautAdded, astronaut.GetType().Name, astronautName)); }
public string AddAstronaut(string astronautType, string astronautName) { IAstronaut astronaut; switch (astronautType) { case "Biologist": astronaut = new Biologist(astronautName); break; case "Geodesist": astronaut = new Geodesist(astronautName); break; case "Meteorologist": astronaut = new Meteorologist(astronautName); break; default: throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); } //Assembly assembly = Assembly.GetExecutingAssembly(); //var type = assembly // .GetTypes() // .FirstOrDefault(t => t.Name == astronautType); //if (type == null) //{ // throw new InvalidOperationException(ExceptionMessages.InvalidAstronautType); //} //var astronaut = (IAstronaut)Activator.CreateInstance(type, astronautName); this.astronautRepository.Add(astronaut); return(string.Format(OutputMessages.AstronautAdded, astronaut.GetType().Name, astronaut.Name)); }