private string LoadValue(XElement xml) { string type = null; XAttribute typeAttribute = xml.Attribute("type"); if (typeAttribute != null) { type = typeAttribute.Value; } switch (type) { case null: case "id": case "an": return(xml.Value); case "dt": DateTime date; return(DateTime.TryParse(xml.Value, out date) ? EdiValue.Date(8, date) : xml.Value); case "tm": DateTime time; if (!DateTime.TryParse(xml.Value, out time)) { return(xml.Value); } int length = Regex.Replace(xml.Value, "[^0-9]", string.Empty).Length; if (xml.Value[1] == ':') { length++; } return(EdiValue.Time(length, time)); case "r": decimal real; if (decimal.TryParse(xml.Value, out real)) { string edi = EdiValue.Real(real); if (Options.DecimalIndicator.HasValue) { edi = edi.Replace('.', Options.DecimalIndicator.Value); } return(edi); } return(xml.Value); default: if (type == null || type.Length != 2 || type[0] != 'n' || !char.IsDigit(type[1])) { return(xml.Value); } int decimals = int.Parse(type.Substring(1)); decimal numeric; return(decimal.TryParse(xml.Value, out numeric) ? EdiValue.Numeric(decimals, numeric) : xml.Value); } }
private bool MapValue(EdiValue node, string type, out string mappedValue) { try { switch (type) { case "id": case "an": mappedValue = node.Value; return(true); case "dt": mappedValue = node.IsoDate; return(true); case "tm": mappedValue = node.IsoTime; return(true); case "r": mappedValue = node.RealValue.ToString(CultureInfo.InvariantCulture); return(true); default: int decimals = int.Parse(type.Substring(1)); mappedValue = node.NumericValue(decimals).ToString(CultureInfo.InvariantCulture); return(true); } } catch (FormatException) { Errors.Add(string.Format("'{0}' is not a valid value of type '{1}'.", node.Value, type)); mappedValue = null; return(false); } }
private bool MapValue(EdiValue node, string type, out string mappedValue) { try { switch (type) { case "id": case "an": mappedValue = node.Value; return true; case "dt": mappedValue = node.IsoDate; return true; case "tm": mappedValue = node.IsoTime; return true; case "r": mappedValue = node.RealValue.ToString(CultureInfo.InvariantCulture); return true; default: int decimals = int.Parse(type.Substring(1)); mappedValue = node.NumericValue(decimals).ToString(CultureInfo.InvariantCulture); return true; } } catch (FormatException) { Errors.Add(string.Format("'{0}' is not a valid value of type '{1}'.", node.Value, type)); mappedValue = null; return false; } }