static void WriteGeneric <TKey, TValue>(XXmlSerializerInternal serializer, XmlWriter writer, Dictionary <TKey, TValue> obj)
 {
     foreach (var item in obj)
     {
         writer.WriteStartElement("Item");
         writer.WriteStartElement("Key");
         serializer.InternalWrite(writer, item.Key, typeof(TKey));
         writer.WriteEndElement();
         writer.WriteStartElement("Value");
         serializer.InternalWrite(writer, item.Value, typeof(TValue));
         writer.WriteEndElement();
         writer.WriteEndElement();
     }
 }
예제 #2
0
 public override void Write(XXmlSerializerInternal serializer, XmlWriter writer, object obj)
 {
     foreach (var field in GetFieldInfos(obj.GetType()))
     {
         writer.WriteStartElement(field.Name);
         serializer.InternalWrite(writer, field.GetValue(obj), field.FieldType);
         writer.WriteEndElement();
     }
 }
 static void WriteGeneric <T>(XXmlSerializerInternal serializer, XmlWriter writer, List <T> obj)
 {
     for (int i = 0; i < obj.Count; ++i)
     {
         writer.WriteStartElement("Item");
         serializer.InternalWrite(writer, obj[i], typeof(T));
         writer.WriteEndElement();
     }
 }
예제 #4
0
        public override void Write(XXmlSerializerInternal serializer, XmlWriter writer, object obj)
        {
            Array arr = (Array)obj;

            if (arr.GetLowerBound(0) != 0)
            {
                throw new XSerializeException("Array low bound must be 0");
            }
            var type         = obj.GetType();
            var element_type = type.GetElementType();

            foreach (var info in arr)
            {
                writer.WriteStartElement("Item");
                serializer.InternalWrite(writer, info, element_type);
                writer.WriteEndElement();
            }
        }
예제 #5
0
        void _Write(XXmlSerializerInternal serializer, XmlWriter writer, object obj, Type type)
        {
            var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)
                         .OrderBy(f => f.Name, StringComparer.Ordinal);

            foreach (var field in fields)
            {
                writer.WriteStartElement(field.Name);
                serializer.InternalWrite(writer, field.GetValue(obj), field.FieldType);
                writer.WriteEndElement();
            }

            if (type.BaseType != null)
            {
                writer.WriteStartElement("__Base__");
                writer.WriteAttributeString("type", type.BaseType.ToString());
                _Write(serializer, writer, obj, type.BaseType);
                writer.WriteEndElement();
            }
        }