Example #1
0
 public override void SerializeNonReference(object graph,
                                            XmlFormatterSerializer serializer)
 {
     foreach (object o in (IEnumerable)graph)
     {
         serializer.WriteStartElement(element_qname.Name, XmlName.Namespace, CurrentNamespace);
         serializer.Serialize(element_type, o);
         serializer.WriteEndElement();
     }
 }
Example #2
0
        public override void Serialize(object graph, XmlFormatterSerializer serializer)
        {
            IXmlSerializable ixs = graph as IXmlSerializable;

            if (ixs == null)
            {
                //FIXME: Throw what exception here?
                throw new SerializationException();
            }

            ixs.WriteXml(serializer.Writer);
        }
Example #3
0
        public override void SerializeNonReference(object graph,
                                                   XmlFormatterSerializer serializer)
        {
            // output item xmlns in advance so that it does not result in excessive xmlns overwrites.
            if (XmlName.Namespace != element_qname.Namespace && element_qname.Namespace != KnownTypeCollection.MSSimpleNamespace)
            {
                serializer.Writer.WriteXmlnsAttribute(null, element_qname.Namespace);
            }

            foreach (object o in (IEnumerable)graph)
            {
                serializer.WriteStartElement(element_qname.Name, XmlName.Namespace, CurrentNamespace);
                serializer.Serialize(element_type, o);
                serializer.WriteEndElement();
            }
        }
Example #4
0
        public virtual void SerializeNonReference(object graph,
                                                  XmlFormatterSerializer serializer)
        {
            foreach (DataMemberInfo dmi in Members)
            {
                FieldInfo    fi = dmi.Member as FieldInfo;
                PropertyInfo pi = fi == null ?
                                  (PropertyInfo)dmi.Member : null;
                Type type = fi != null ?
                            fi.FieldType : pi.PropertyType;
                object value = fi != null?
                               fi.GetValue(graph) :
                                   pi.GetValue(graph, null);

                serializer.WriteStartElement(dmi.XmlName, dmi.XmlRootNamespace, dmi.XmlNamespace);
                serializer.Serialize(type, value);
                serializer.WriteEndElement();
            }
        }
        /*
         *  when writeContentOnly is true, then the input XmlWriter
         *  must be at element state. This is to write possible
         *  xsi:nil.
         *
         *  rootType determines the top-level element QName (thus
         *  it is ignored when writeContentOnly is true).
         *
         *  preserveObjectReferences indicates that whether the
         *  output should contain ms:Id or not.
         *  (http://schemas.microsoft.com/2003/10/Serialization/)
         */
        public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
        {
            if (graph == null)
            {
                return;
            }

            int startTypeCount = known_types.Count;

            XmlFormatterSerializer.Serialize(writer, graph,
                                             type, known_types,
                                             ignore_ext, max_items, root_ns.Value, preserve_refs, DataContractResolver, default_resolver);

            // remove temporarily-added known types for
            // rootType and object graph type.
            while (known_types.Count > startTypeCount)
            {
                known_types.RemoveAt(startTypeCount);
            }
        }
Example #6
0
        public override void Serialize(object graph,
                                       XmlFormatterSerializer serializer)
        {
            if (flag_attr)
            {
                long   val = Convert.ToInt64(graph);
                string s   = null;
                foreach (EnumMemberInfo emi in enum_members)
                {
                    long f = Convert.ToInt64(emi.Value);
                    if (f == val)
                    {
                        s = emi.XmlName;
                        break;
                    }
                    if ((f & val) == f)
                    {
                        s += (s != null ? " " : String.Empty) + emi.XmlName;
                    }
                }
                if (s != null)
                {
                    serializer.Writer.WriteString(s);
                }
                return;
            }
            else
            {
                foreach (EnumMemberInfo emi in enum_members)
                {
                    if (Enum.Equals(emi.Value, graph))
                    {
                        serializer.Writer.WriteString(emi.XmlName);
                        return;
                    }
                }
            }

            throw new SerializationException(String.Format(
                                                 "Enum value '{0}' is invalid for type '{1}' and cannot be serialized.", graph, RuntimeType));
        }
Example #7
0
 public override void SerializeNonReference(object graph,
                                            XmlFormatterSerializer serializer)
 {
     if (add_method != null)               // generic
     {
         if (pair_type == null)
         {
             pair_type           = typeof(KeyValuePair <,>).MakeGenericType(add_method.DeclaringType.GetGenericArguments());
             pair_key_property   = pair_type.GetProperty("Key");
             pair_value_property = pair_type.GetProperty("Value");
         }
         foreach (object p in (IEnumerable)graph)
         {
             serializer.WriteStartElement(item_qname.Name, item_qname.Namespace, CurrentNamespace);
             serializer.WriteStartElement(key_qname.Name, key_qname.Namespace, CurrentNamespace);
             serializer.Serialize(pair_key_property.PropertyType, pair_key_property.GetValue(p, null));
             serializer.WriteEndElement();
             serializer.WriteStartElement(value_qname.Name, value_qname.Namespace, CurrentNamespace);
             serializer.Serialize(pair_value_property.PropertyType, pair_value_property.GetValue(p, null));
             serializer.WriteEndElement();
             serializer.WriteEndElement();
         }
     }
     else                 // non-generic
     {
         foreach (DictionaryEntry p in (IEnumerable)graph)
         {
             serializer.WriteStartElement(item_qname.Name, item_qname.Namespace, CurrentNamespace);
             serializer.WriteStartElement(key_qname.Name, key_qname.Namespace, CurrentNamespace);
             serializer.Serialize(key_type, p.Key);
             serializer.WriteEndElement();
             serializer.WriteStartElement(value_qname.Name, value_qname.Namespace, CurrentNamespace);
             serializer.Serialize(value_type, p.Value);
             serializer.WriteEndElement();
             serializer.WriteEndElement();
         }
     }
 }
Example #8
0
        public virtual void Serialize(object graph,
                                      XmlFormatterSerializer serializer)
        {
            string label;

            if (serializer.TrySerializeAsReference(IsReference, graph, out label))
            {
                return;
            }
            else if (serializer.SerializingObjects.Contains(graph))
            {
                throw new SerializationException(String.Format("Circular reference of an object in the object graph was found: '{0}' of type {1}", graph, graph.GetType()));
            }
            serializer.SerializingObjects.Add(graph);

            if (label != null)
            {
                serializer.Writer.WriteAttributeString("z", "Id", KnownTypeCollection.MSSimpleNamespace, label);
            }

            SerializeNonReference(graph, serializer);

            serializer.SerializingObjects.Remove(graph);
        }