Exemple #1
0
 private void MarshalAs(object value, Type type)
 {
     if (type.Equals(typeof(object)))
     {
         return;
     }
     FieldInfo[] fields = type.GetFields(Constants.BINDINGFlags);
     foreach (var field in fields)
     {
         string nodeName = field.Name;
         Match  match    = Constants.AutoPropertyNamePattern.Match(field.Name);
         if (match.Success)
         {
             nodeName = match.Result("$1");
         }
         if (field.GetCustomAttributes(typeof(DontSerialiseAttribute), true).Length != 0)
         {
             continue;
         }
         if (field.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length != 0)
         {
             continue;
         }
         if (typeof(MulticastDelegate).IsAssignableFrom(field.FieldType))
         {
             continue;
         }
         writer.StartNode(nodeName);
         WriteClassNameIfNeedBe(value, field);
         context.ConvertAnother(field.GetValue(value));
         writer.EndNode();
     }
     MarshalAs(value, type.BaseType);
 }
        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();
        }
Exemple #3
0
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            byte[] bytes  = (byte[])value;
            string base64 = Convert.ToBase64String(bytes);

            writer.StartNode("byte-array");

            writer.SetValue(base64);

            writer.EndNode();
        }
 private void MarshalAs(object containingObject, Type type, XStreamWriter writer, MarshallingContext context)
 {
     if (type.Equals(typeof(object))) return;
     foreach (var field in mapper.GetSerializableFieldsIn(type))
     {
         field.WriteValueOn(writer, containingObject);
         context.ConvertAnother(field.GetObjectFrom(containingObject));
         writer.EndNode();
     }
     MarshalAs(containingObject, type.BaseType, writer, context);
 }
        public void ConvertOriginal(object value)
        {
            if (value == null)
            {
                // TODO: Make this a configuration option
                // Don't export null values.
                return;
            }

            StartNode(value);
            ConvertAnother(value);
            writer.EndNode();
        }
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IDictionary dictionary = (IDictionary)value;

            DoSpecificStuff(dictionary, writer);
            foreach (DictionaryEntry entry in dictionary)
            {
                writer.StartNode("entry");
                WriteNode(writer, context, BaseDictionaryConverter <Hashtable> .KEY, entry.Key);
                WriteNode(writer, context, BaseDictionaryConverter <Hashtable> .VALUE, entry.Value);
                writer.EndNode();
            }
        }
        public void ToXml(object value, XStreamWriter writer, MarshallingContext context)
        {
            IDictionary dictionary = (IDictionary)value;

            DoSpecificStuff(dictionary, writer);
            foreach (DictionaryEntry entry in dictionary)
            {
                writer.StartNode("entry");

                context.ConvertOriginal(entry.Key);
                context.ConvertOriginal(entry.Value);

                writer.EndNode();
            }
        }
        private void MarshalAs(object value, Type type)
        {
            if (type.Equals(typeof(object)) || value == null)
            {
                return;
            }

            FieldInfo[] fields = type.GetFields(Constants.BINDINGFlags);
            foreach (FieldInfo field in fields)
            {
                if (field.GetCustomAttributes(typeof(DontSerialiseAttribute), true).Length != 0)
                {
                    continue;
                }
                if (field.GetCustomAttributes(typeof(XmlIgnoreAttribute), true).Length != 0)
                {
                    continue;
                }
                if (typeof(MulticastDelegate).IsAssignableFrom(field.FieldType))
                {
                    continue;
                }

                string nodeName = field.Name;
                if (nodeName.StartsWith("__") || nodeName == "_id")
                {
                    // Skip internal/private autogenerated members
                    continue;
                }

                Match autoPropertyMatch = Constants.AutoPropertyNamePattern.Match(field.Name);
                Match javaPropertyMatch = Constants.JavaInternalPropertyNamePattern.Match(field.Name);
                if (autoPropertyMatch.Success)
                {
                    nodeName = autoPropertyMatch.Result("$1");
                }
                else if (javaPropertyMatch.Success)
                {
                    nodeName = javaPropertyMatch.Result("$1");
                }

                object fieldValue = field.GetValue(value);
                if (fieldValue != null)
                {
                    writer.StartNode(nodeName);
                    WriteClassNameIfNeedBe(value, field);
                    context.ConvertAnother(fieldValue);
                    writer.EndNode();
                }
            }

            PropertyInfo[] properties = type.GetProperties(Constants.BINDINGFlags);
            foreach (PropertyInfo property in properties)
            {
                // Only serialize propertied that are explicitly set
                if (property.GetCustomAttributes(typeof(SerialisedProperty), true).Length != 1)
                {
                    continue;
                }

                object fieldValue = property.GetValue(value);
                if (fieldValue != null)
                {
                    writer.StartNode(property.Name);
                    context.ConvertAnother(fieldValue);
                    writer.EndNode();
                }
            }

            MarshalAs(value, type.BaseType);
        }
Exemple #9
0
 public void ConvertOriginal(object value)
 {
     StartNode(value);
     ConvertAnother(value);
     writer.EndNode();
 }