private void StartNode(object value)
        {
            if (value == null)
            {
                Console.Write("NULL");
            }

            Type type = value != null?value.GetType() : typeof(object);

            foreach (Alias alias in aliases)
            {
                string nodeAlias;
                if (alias.TryGetAlias(type, out nodeAlias))
                {
                    writer.StartNode(nodeAlias);
                    return;
                }
            }

            // TODO:  Look into refactoring the Xmlifier to be more cross-platform friendly
            if (value is IList)
            {
                writer.StartNode("list");
            }
            else if (value is String)
            {
                writer.StartNode("string");
            }
            else
            {
                writer.StartNode(Xmlifier.XmlifyNode(type));
            }
            //  classType is not valid for cross platform usage
            //writer.WriteAttribute(Attributes.classType, type.AssemblyQualifiedName);
        }
Exemple #2
0
        private void StartNode(object value)
        {
            Type type = value != null?value.GetType() : typeof(object);

            foreach (Alias alias in aliases)
            {
                string nodeAlias;
                if (alias.TryGetAlias(type, out nodeAlias))
                {
                    writer.StartNode(nodeAlias);
                    return;
                }
            }
            writer.StartNode(Xmlifier.XmlifyNode(type));
            writer.WriteAttribute(Attributes.classType, type.AssemblyQualifiedName);
        }
Exemple #3
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);
 }
 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();
        }
Exemple #6
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();
        }
        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();
            }
        }
 public void WriteOn(XStreamWriter writer)
 {
     writer.StartNode(serializedClassName);
     attributes.ForEach(x => x.WriteOn(writer));
 }
        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);
        }