/// <summary> /// Graph object <paramref name="o"/> onto the stream /// </summary> public void Graph(XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // Graph ANY QTYFormatter baseFormatter = new QTYFormatter(); baseFormatter.Host = this.Host; // Null ? IAny anyInstance = o as IAny; IPrimitiveDataValue pdv = o as IPrimitiveDataValue; IRealValue rv = o as IRealValue; // Format if (pdv.Value != null && anyInstance.NullFlavor == null) { if (rv == null || rv.Precision == 0) { s.WriteAttributeString("value", Util.ToWireFormat(pdv.Value)); } else if (rv != null) { s.WriteAttributeString("value", String.Format(DatatypeR2Formatter.FormatterCulture, String.Format("{{0:0.{0}}}", new String('0', rv.Precision), DatatypeR2Formatter.FormatterCulture.NumberFormat.NumberDecimalSeparator), rv.Value)); } } // Format the base baseFormatter.Graph(s, o, result); }
/// <summary> /// Graph object <paramref name="o"/> onto <paramref name="s"/> /// </summary> /// <param name="s">The stream being graphed to</param> /// <param name="o">The object being graphed</param> /// <param name="result">The result of the graph operation</param> public void Graph(System.Xml.XmlWriter s, object o, DatatypeR2FormatterGraphResult result) { // Graph the QTY portions QTYFormatter qty = new QTYFormatter(); qty.Host = this.Host; qty.Graph(s, o, result); // Any null flavors IAny anyO = o as IAny; IPrimitiveDataValue ipdv = o as IPrimitiveDataValue; if (anyO.NullFlavor != null) { return; } // PDV Value does not support value if (ipdv.Value != null) { result.AddResultDetail(new NotPermittedDatatypeR2EntityResultDetail(MARC.Everest.Connectors.ResultDetailType.Warning, "Value", "RTO", s.ToString())); } // Get the numerator / denominator PropertyInfo numeratorProperty = o.GetType().GetProperty("Numerator"), denominatorProperty = o.GetType().GetProperty("Denominator"); object numerator = numeratorProperty.GetValue(o, null), denominator = denominatorProperty.GetValue(o, null); // Serialize the numerator if (numerator != null) { s.WriteStartElement("numerator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(numerator.GetType()); // Write the type if (this.Host.Host == null) { s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); } else { s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); } var hostResult = this.Host.Graph(s, (IGraphable)numerator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } // Serialize Denominator if (denominator != null) { s.WriteStartElement("denominator", "urn:hl7-org:v3"); // Write the XSI type string xsiTypeName = DatatypeR2Formatter.CreateXSITypeName(denominator.GetType()); // Write the type if (this.Host.Host == null) { s.WriteAttributeString("type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); } else { s.WriteAttributeString("xsi", "type", DatatypeR2Formatter.NS_XSI, xsiTypeName.ToString()); } var hostResult = this.Host.Graph(s, (IGraphable)denominator); result.Code = hostResult.Code; result.AddResultDetail(hostResult.Details); s.WriteEndElement(); } }