Ejemplo n.º 1
0
        /// <summary>
        /// Graph the SXCM to the console
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            // Output the object
            Type   t    = o.GetType();
            ANY    any  = (ANY)o;
            object oper = t.GetProperty("Operator").GetValue(o, null),
                   valu = t.GetProperty("Value").GetValue(o, null);

            if (oper != null && any.NullFlavor == null)
            {
                s.WriteAttributeString("operator", Util.ToWireFormat(oper));
            }
            // Format the object
            var formatter = DatatypeFormatter.GetFormatter(valu.GetType());

            formatter.Host = this.Host;
            formatter.Graph(s, valu, result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse an SXCM from the wire
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Determine the generic type formatter
            var formatter = DatatypeFormatter.GetFormatter(GenericArguments[0]);

            // Create the return value
            Type            sxcmType = typeof(SXCM <>);
            Type            genType  = sxcmType.MakeGenericType(GenericArguments);
            ConstructorInfo ci       = genType.GetConstructor(Type.EmptyTypes);
            Object          retVal   = null;

            if (ci != null)
            {
                retVal = ci.Invoke(null);
            }
            else
            {
                throw new ArgumentException("Constructor on type must have a parameterless constructor");
            }

            // Operator
            if (s.GetAttribute("operator") != null)
            {
                genType.GetProperty("Operator").SetValue(retVal, Util.FromWireFormat(s.GetAttribute("operator"), typeof(SetOperator)), null);
            }
            // Value
            if (formatter != null)
            {
                formatter.Host = this.Host;
                var value = formatter.Parse(s, result);
                genType.GetProperty("Value").SetValue(retVal, value, null);

                if (value != null)
                {
                    ((ANY)retVal).NullFlavor = ((ANY)value).NullFlavor;
                    ((ANY)retVal).Flavor     = ((ANY)value).Flavor;
                    ((ANY)value).NullFlavor  = null;
                    ((ANY)value).Flavor      = null;
                }
            }


            return(retVal);
        }