/// <summary> /// Parse object from <paramref name="s"/> /// </summary> /// <param name="s">The XmlReader to graph from</param> public virtual object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { IResultDetail[] details = null; CV <String> retVal = CDFormatter.Parse <CV <String> >(s, Host, result); return(retVal); }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse from</param> /// <returns>The parsed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { // Read value before we lose context string valStr = s.GetAttribute("value"); // Create retval PQR retVal = CDFormatter.Parse <PQR>(s, Host, result); // Precision is not supported in R1, but is still useful to have so // we will report the precision of the data that was on the wire if (valStr != null && valStr.Contains(".")) { retVal.Precision = valStr.Length - valStr.IndexOf(".") - 1; } else { retVal.Precision = 0; } retVal.Value = (decimal?)Util.FromWireFormat(valStr, typeof(decimal?)); // Validate ANYFormatter fmtr = new ANYFormatter(); string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name; fmtr.Validate(retVal, pathName, result); return(retVal); }
/// <summary> /// Parse function /// </summary> /// <param name="s"></param> /// <returns></returns> public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { var retVal = CDFormatter.Parse <CD <String> >(s, Host, result); CO instance = new CO(); instance.Code = retVal; // Propogate if (instance.Code != null) { instance.Flavor = instance.Code.Flavor; instance.NullFlavor = instance.Code.NullFlavor; instance.Code.NullFlavor = null; instance.Code.Flavor = null; } base.Validate(instance, s.ToString(), result); return(instance); }
/// <summary> /// Graph object <paramref name="o"/> onto stream <paramref name="s"/> /// </summary> /// <param name="s">The stream to graph to</param> /// <param name="o">The object to graph</param> public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result) { ANYFormatter baseFormatter = new ANYFormatter(); baseFormatter.Graph(s, o, result); // Graph the base data // If there is no null flavor then graph the rest of the object object invertedValue = o.GetType().GetProperty("Inverted").GetValue(o, null), nameValue = o.GetType().GetProperty("Name").GetValue(o, null), valueValue = o.GetType().GetProperty("Value").GetValue(o, null); // Graph the structural attributes s.WriteAttributeString("inverted", Util.ToWireFormat(invertedValue)); // Graph the non-structural elements if (nameValue != null) { s.WriteStartElement("name"); CVFormatter cdFormatter = new CVFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, nameValue, result); s.WriteEndElement(); // end name } if (valueValue != null) { s.WriteStartElement("value"); CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; cdFormatter.Graph(s, valueValue, result); s.WriteEndElement(); // end value } }
/// <summary> /// Parse an object from <paramref name="s"/> /// </summary> /// <param name="s">The stream to parse the object from</param> /// <returns>The constructed object</returns> public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result) { Type crGenericType = typeof(CR <>).MakeGenericType(GenericArguments); ConstructorInfo ci = crGenericType.GetConstructor(Type.EmptyTypes); if (ci == null) { throw new InvalidOperationException("Type being parsed must have parameterless constructor"); } object instance = ci.Invoke(null); // NullFlavor ? if (s.GetAttribute("nullFlavor") != null) { ((ANY)instance).NullFlavor = (NullFlavor)Util.FromWireFormat(s.GetAttribute("nullFlavor"), typeof(NullFlavor)); } else { // JF - Supported only in CA extensions to R1 data types if (s.GetAttribute("specializationType") != null && result.CompatibilityMode == DatatypeFormatterCompatibilityMode.Canadian) { ((ANY)instance).Flavor = s.GetAttribute("specializationType"); } // Inverted if (s.GetAttribute("inverted") != null) { crGenericType.GetProperty("Inverted").SetValue(instance, Util.FromWireFormat(s.GetAttribute("inverted"), typeof(bool)), null); } #region Elements if (!s.IsEmptyElement) { int sDepth = s.Depth; string sName = s.Name; s.Read(); // string Name while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName)) { string oldName = s.Name; // Name try { if (s.LocalName == "name") // Format using ED { CVFormatter cvFormatter = new CVFormatter(); cvFormatter.Host = this.Host; cvFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Name").SetValue(instance, Util.FromWireFormat(cvFormatter.Parse(s, result), crGenericType.GetProperty("Name").PropertyType), null); } else if (s.LocalName == "value") { CDFormatter cdFormatter = new CDFormatter(); cdFormatter.Host = this.Host; cdFormatter.GenericArguments = this.GenericArguments; crGenericType.GetProperty("Value").SetValue(instance, Util.FromWireFormat(cdFormatter.Parse(s, result), crGenericType.GetProperty("Value").PropertyType), null); } } catch (MessageValidationException e) { result.AddResultDetail(new MARC.Everest.Connectors.ResultDetail(MARC.Everest.Connectors.ResultDetailType.Error, e.Message, s.ToString(), e)); } finally { if (s.Name == oldName) { s.Read(); } } } } #endregion } return(instance); }