Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public T ParseAttributes <T>(XmlReader r, DatatypeR2FormatterParseResult result) where T : ANY, IPrimitiveDataValue, IQuantity, new()
        {
            string val = null;

            // Get the value
            if (r.GetAttribute("value") != null)
            {
                val = r.GetAttribute("value");
            }

            // Parse the QTY part
            QTYFormatter baseFormatter = new QTYFormatter();

            baseFormatter.Host = this.Host;

            // Parse attributes part of QTY
            T retVal = baseFormatter.ParseAttributes <T>(r, result);

            IRealValue rvRetVal = retVal as IRealValue;

            // If the value was interpreted
            if (!String.IsNullOrEmpty(val))
            {
                try
                {
                    retVal.Value = Util.FromWireFormat(val, retVal.GetType().GetProperty("Value").PropertyType);
                    if (rvRetVal != null && val.Contains(DatatypeR2Formatter.FormatterCulture.NumberFormat.NumberDecimalSeparator))
                    {
                        rvRetVal.Precision = val.Length - val.IndexOf(DatatypeR2Formatter.FormatterCulture.NumberFormat.NumberDecimalSeparator) - 1;
                    }
                }
                catch (Exception e)
                {
                    result.Code = ResultCode.Error;
                    result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, r.ToString(), e));
                }
            }

            // REturn the retVal
            return(retVal);
        }