public void TestNumeric() { var tnumeric = new TNumeric("NUM"); tnumeric.Set("0,255"); Assert.AreEqual(0.255f, tnumeric.value); tnumeric.Set(""); Assert.AreEqual(0f, tnumeric.value); var tsum = new TNumeric("SUM") { function = TNumeric.getFuncByString("SUM") }; tsum.Set("0,5"); tsum.Set("1,5"); Assert.AreEqual(2f, tsum.value); tsum = new TNumeric("WAT") { function = TNumeric.getFuncByString("Invalid?") }; tsum.Set("0,5"); tsum.Set("1,5"); Assert.AreNotEqual(2f, tsum.value); }
protected TVariable getVar(XElement xml, bool dynamic) { var name = xml.Attribute("name")?.Value ?? throw new NullReferenceException("Variable attribute 'name' can't be null!"); var ctype = xml.Attribute("type")?.Value ?? "string"; TVariable variable; switch (ctype) { case "numeric": variable = new TNumeric(name); break; case "date": variable = new TDate(name); break; default: variable = new TVariable(name); break; } variable.x = Int32.Parse(xml.Attribute("X")?.Value ?? throw new NullReferenceException("Variable attribute 'X' can't be null!")); if (!dynamic) { variable.y = Int32.Parse(xml.Attribute("Y")?.Value ?? throw new NullReferenceException("Variable attribute 'Y' can't be null!")); } variable.dynamic = dynamic; if (variable is TNumeric tnumeric) { var function = xml.Attribute("function"); if (function != null) { tnumeric.function = TNumeric.getFuncByString(function.Value); } } if (variable is TDate tdate) { var lastday = xml.Attribute("lastday"); var language = xml.Attribute("language"); var format = xml.Attribute("format"); if (lastday != null) { tdate.lastday = Boolean.Parse(lastday.Value); } if (language != null) { tdate.language = language.Value; } if (format != null) { tdate.format = format.Value; } } var regex_pattern = xml.Attribute("regex_pattern"); if (regex_pattern != null) { variable.regex_pattern = new Regex(regex_pattern.Value, RegexOptions.Compiled); var regex_group = xml.Attribute("regex_group"); variable.regex_group = int.Parse(regex_group?.Value ?? "1"); } return(variable); }