public ConfigurationManager AddConfig(TabPage page) { var subControls = page.Controls.OfType <Control>(); var config = new Configuration() { ConfigurationName = page.Text, Authentication = subControls.Where(c => c.Name == $"txtAuthentication_{page.Text}") .Select( c => c.Text) .FirstOrDefault(), Url = subControls.Where(c => c.Name == $"txtUrl_{page.Text}") .Select(c => c.Text) .FirstOrDefault(), StopMoney = subControls.Where(c => c.Name == $"txtMoneyWarning_{page.Text}") .Select(c => c.Text) .FirstOrDefault(), IsMoneyWarning = (subControls.Where(c => c.Name == $"cbMoneyWarning_{page.Text}") .FirstOrDefault() as MaterialSkin.Controls.MaterialCheckBox).Checked, IsCycle = (subControls.Where(c => c.Name == $"cblblIsCycle_{page.Text}") .FirstOrDefault() as MaterialSkin.Controls.MaterialCheckBox).Checked, Proxy = new Proxy() { IP = subControls.Where(c => c.Name == $"pnlProxy_{page.Text}") .Select(c => c.Controls) .FirstOrDefault() .OfType <System.Windows.Forms.Control>() .Where(c => c.Name == $"txtIP_{page.Text}") .Select(c => c.Text).FirstOrDefault(), Port = subControls.Where(c => c.Name == $"pnlProxy_{page.Text}") .Select(c => c.Controls) .FirstOrDefault() .OfType <System.Windows.Forms.Control>() .Where(c => c.Name == $"txtPort_{page.Text}") .Select(c => c.Text).FirstOrDefault() }, Action = new List <CustomAction>() }; var listView = subControls.Where(c => c.Name == $"mlvData_{page.Text}") .FirstOrDefault() as MaterialSkin.Controls.MaterialListView; if (listView != null) { foreach (ListViewItem item in listView.Items) { CustomAction action = new CustomAction() { ActionIndex = item.SubItems[0].Text, BetType = CustomAction.ToBet(item.SubItems[1].Text), Delay = item.SubItems[2].Text, Money = item.SubItems[3].Text }; config.Action.Add(action); } } this.Configs[page.Text] = config; return(this); }