public string AttachFragment(string[] parameters) { string type = parameters[0]; string name = parameters[1]; int pressureAffection = int.Parse(parameters[2]); try { if (type != FragmentType.Cooling.ToString() && type != FragmentType.Nuclear.ToString()) { throw new ArgumentException(); } IFragment fragment = null; switch (type) { case "Cooling": fragment = new CoolingFragment(type, name, pressureAffection); break; case "Nuclear": fragment = new NuclearFragment(type, name, pressureAffection); break; } return(this.selectedCore.AttachFragment(fragment)); } catch (Exception) { return($"Failed to attach Fragment {name}!"); } }
public IFragment CreateFragment(FragmentType fragmentType, string name, int pressureAffection) { IFragment fragment = null; switch (fragmentType) { case FragmentType.Cooling: fragment = new CoolingFragment(name, pressureAffection); break; case FragmentType.Nuclear: fragment = new NuclearFragment(name, pressureAffection); break; } return fragment; }