private void ConvertObject(object value)
        {
            if (value == null)
            {
                // TODO: Make this a configuration option
                // Don't export null values.
                return;
            }

            if (alreadySerialised.ContainsKey(value))
            {
                // Reference by ID, not path
                writer.WriteAttribute(Attributes.reference, alreadySerialised[value]);
            }
            else
            {
                // Store the ID of the object
                int index = alreadySerialised.Count + 1;
                alreadySerialised.Add(value, index.ToString());

                // Write attribute for own id
                writer.WriteAttribute(Attributes.id, index.ToString());

                new Marshaller(writer, this).Marshal(value);
            }
        }
Exemplo n.º 2
0
 private void ConvertObject(object value)
 {
     if (alreadySerialised.ContainsKey(value))
     {
         writer.WriteAttribute(Attributes.references, alreadySerialised[value]);
     }
     else
     {
         alreadySerialised.Add(value, writer.CurrentPath);
         new Marshaller(writer, this).Marshal(value);
     }
 }
Exemplo n.º 3
0
 public void Marshall(object value, XStreamWriter writer, MarshallingContext context)
 {
     IList list = (IList) value;
     writer.WriteAttribute(LIST_TYPE, value.GetType().FullName);
     foreach (object o in list)
         context.ConvertOriginal(o);
 }
Exemplo n.º 4
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context) {
     Array array = (Array) value;
     string typeName = value.GetType().AssemblyQualifiedName;
     int lastIndexOfBrackets = typeName.LastIndexOf("[]");
     string arrayType = string.Concat(typeName.Substring(0, lastIndexOfBrackets), typeName.Substring(lastIndexOfBrackets + 2));
     writer.WriteAttribute(ARRAY_TYPE, arrayType);
     foreach (object o in array)
         context.ConvertOriginal(o);
 }
Exemplo n.º 5
0
 public void WriteValueOn(XStreamWriter writer, object value)
 {
     writer.StartNode(SerializedName);
     object fieldValue = GetObjectFrom(value);
     if (fieldValue == null) return;
     Type actualType = fieldValue.GetType();
     if (!FieldType.Equals(actualType))
         writer.WriteAttribute(XsAttribute.classType, actualType.AssemblyQualifiedName);
 }
        private static void WriteNode(XStreamWriter writer, MarshallingContext context, string node, object value)
        {
            writer.StartNode(node);
            Type type = value != null?value.GetType() : typeof(object);

            writer.WriteAttribute(Attributes.classType, type.AssemblyQualifiedName);
            context.ConvertAnother(value);
            writer.EndNode();
        }
Exemplo n.º 7
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IList list = (IList)value;

            writer.WriteAttribute(LIST_TYPE, value.GetType().FullName);
            foreach (object o in list)
            {
                context.ConvertOriginal(o);
            }
        }
Exemplo n.º 8
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            Array  array               = (Array)value;
            string typeName            = value.GetType().AssemblyQualifiedName;
            int    lastIndexOfBrackets = typeName.LastIndexOf("[]");
            string arrayType           = string.Concat(typeName.Substring(0, lastIndexOfBrackets), typeName.Substring(lastIndexOfBrackets + 2));

            writer.WriteAttribute(ARRAY_TYPE, arrayType);
            foreach (object o in array)
            {
                context.ConvertOriginal(o);
            }
        }
Exemplo n.º 9
0
        private void WriteClassNameIfNeedBe(object value, FieldInfo field)
        {
            object fieldValue = field.GetValue(value);

            if (fieldValue == null)
            {
                return;
            }
            Type actualType = fieldValue.GetType();

            if (!field.FieldType.Equals(actualType))
            {
                writer.WriteAttribute(Attributes.classType, actualType.AssemblyQualifiedName);
            }
        }
Exemplo n.º 10
0
        private void WriteClassNameIfNeedBe(object value, FieldInfo field)
        {
            object fieldValue = field.GetValue(value);

            if (fieldValue == null)
            {
                return;
            }
            Type actualType = fieldValue.GetType();

            if (!field.FieldType.Equals(actualType))
            {
                // TODO: Examine the behavior of this
                //  classType is not valid for cross platform usage
                writer.WriteAttribute(Attributes.classType, actualType.AssemblyQualifiedName);
            }
        }
Exemplo n.º 11
0
 public void Marshall(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(XsAttribute.AttributeType, value.GetType().AssemblyQualifiedName);
     writer.SetValue(value.ToString());
 }
Exemplo n.º 12
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(Attributes.AttributeType, value.GetType().AssemblyQualifiedName);
     writer.SetValue(value.ToString());
 }
Exemplo n.º 13
0
 public void WriteOn(XStreamWriter writer)
 {
     writer.WriteAttribute(name, value);
 }
Exemplo n.º 14
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context) {
     writer.WriteAttribute(Attributes.Null, true.ToString());
 }
Exemplo n.º 15
0
 public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
 {
     writer.WriteAttribute(Attributes.Null, true.ToString());
 }