public OptionError GetValue <T>(string name, ref T value, string groupName = null, bool strict = true) { SavedElement foundElement = null; SavedGroup foundGroup = GetGroup(groupName); OptionError error = OptionError.NoError; if (foundGroup != null) { foreach (SavedElement element in foundGroup.elements) { if (element.name == name) { foundElement = element; break; } } if (foundElement != null) { try { if (strict) { if (foundElement.value.GetType() == typeof(T)) { value = (T)Convert.ChangeType(foundElement.value, typeof(T)); } else { error = OptionError.CastFailed; } } else { value = (T)Convert.ChangeType(foundElement.value, typeof(T)); } } catch { error = OptionError.CastFailed; } } else { error = OptionError.OptionNotFound; } } else { error = OptionError.GroupNotFound; } return(error); }
private void CalcButton_Click(object sender, EventArgs e) { choice = DevelopmentOptions.Text; if (choice != "") { rate = 50; hours = int.Parse(HoursText.Text); subtotal = hours * rate; total = subtotal * 1.20; vattaken = (total - subtotal); SubTotal.Text = "£" + subtotal.ToString(); VATAmount.Text = "£" + vattaken.ToString(); PaymentDue.Text = "£" + total.ToString(); } else { OptionError.Show(); } }
private void DevelopementOptions_Click(object sender, EventArgs e) { OptionError.Hide(); }