private void btnNewAdd_Click(object sender, EventArgs e) { switch (_editingFieldIndex) { case null when Program.FieldsList.Any(fli => fli.Name == txtName.Text): MessageBox.Show( $@"There already is a field named {txtName.Text}. Field names should be unique.", @"Gmail Scraper - add field", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; case null: Program.FieldsList.Add(new FieldToFind { Name = txtName.Text, Regex = txtRegexPattern.Text, GroupNumber = (int)numericUpDown1.Value, Required = cbRequired.Checked }); break; default: { FieldToFind f = Program.FieldsList[_editingFieldIndex.Value]; f.Name = txtName.Text; f.Regex = txtRegexPattern.Text; f.GroupNumber = (int)numericUpDown1.Value; f.Required = cbRequired.Checked; _editingFieldIndex = null; break; } } this.SetFieldsToFind(); pnlNewField.Visible = false; Settings.Default.FieldsToFind = JsonConvert.SerializeObject(Program.FieldsList); Settings.Default.Save(); }