Exemplo n.º 1
0
        public void WriteTextContent(TextContentAttribute attribute, object writer,
                                     object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            var current = serializerData.Convert <XElement>();

            current.Value = ObjectUtil.ToString(info.Converter, value, settings);
        }
Exemplo n.º 2
0
        public void WriteTextContent(TextContentAttribute attribute, object writer,
                                     object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlWriter xmlWriter = writer.Convert <XmlWriter>();

            xmlWriter.WriteString(ObjectUtil.ToString(info.Converter, value, settings));
        }
        private static void SetValue(object writer, ObjectPropertyInfo info, string fieldName,
                                     object value, WriteSettings settings)
        {
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();

            builder.Add(fieldName, ObjectUtil.ToString(info.Converter, value, settings));
        }
Exemplo n.º 4
0
        public void WriteComplexContent(ComplexContentAttribute attribute, object writer,
                                        object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlWriter xmlWriter = writer.Convert <XmlWriter>();
            string    text      = ObjectUtil.ToString(info.Converter, value, settings);

            WriteComplexContent(xmlWriter, text);
        }
Exemplo n.º 5
0
        public void WriteComplexElement(SimpleComplexElementAttribute attribute, object writer,
                                        object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            var      current  = serializerData.Convert <XElement>();
            string   xmlValue = ObjectUtil.ToString(info.Converter, value, settings);
            XElement child    = string.IsNullOrEmpty(xmlValue) ? null : XElement.Parse(xmlValue);
            XElement element  = new XElement(info.QName.ToXName(), child);

            current.Add(element);
        }
Exemplo n.º 6
0
 private static void WriteDictionary(IDictionary dict, JsonWriter jsonWriter,
                                     ITkTypeConverter converter, WriteSettings settings)
 {
     jsonWriter.WriteStartObject();
     foreach (DictionaryEntry item in dict)
     {
         jsonWriter.WritePropertyName(item.Key.ToString());
         jsonWriter.WriteValue(ObjectUtil.ToString(converter, item.Value, settings));
     }
     jsonWriter.WriteEndObject();
 }
Exemplo n.º 7
0
        public void WriteComplexContent(ComplexContentAttribute attribute, object writer,
                                        object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            var    current  = serializerData.Convert <XElement>();
            string xmlValue = ObjectUtil.ToString(info.Converter, value, settings);

            if (!string.IsNullOrEmpty(xmlValue))
            {
                XElement child = XElement.Parse(xmlValue);
                current.Add(child);
            }
        }
Exemplo n.º 8
0
        public void WriteComplexElement(SimpleComplexElementAttribute attribute, object writer,
                                        object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlWriter   xmlWriter   = writer.Convert <XmlWriter>();
            PrefixTable prefixTable = serializerData.Convert <PrefixTable>();

            WriteStartElement(xmlWriter, info.QName, prefixTable);
            string data = ObjectUtil.ToString(info.Converter, value, settings);

            WriteComplexContent(xmlWriter, data);
            xmlWriter.WriteEndElement();
        }
Exemplo n.º 9
0
        private static void SetValue(object writer, string fieldName, object value,
                                     ObjectPropertyInfo info, WriteSettings settings)
        {
            DataRow row = writer.Convert <DataRow>();

            try
            {
                row[fieldName] = ObjectUtil.ToString(info.Converter, value, settings);
            }
            catch
            {
            }
        }
Exemplo n.º 10
0
        public void WriteElement(SimpleElementAttribute attribute, object writer,
                                 object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (!attribute.IsMultiple && ObjectUtil.IsDefaultValue(attribute.DefaultValue, value))
            {
                return;
            }

            var      current = serializerData.Convert <XElement>();
            XElement element = new XElement(info.QName.ToXName(),
                                            ObjectUtil.ToString(info.Converter, value, settings));

            current.Add(element);
        }
Exemplo n.º 11
0
        public void WriteAttribute(SimpleAttributeAttribute attribute, object writer,
                                   object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (ObjectUtil.IsDefaultValue(attribute.DefaultValue, value))
            {
                return;
            }

            XName      name    = info.QName.ToXName();
            XAttribute attr    = new XAttribute(name, ObjectUtil.ToString(info.Converter, value, settings));
            XElement   current = serializerData.Convert <XElement>();

            current.Add(attr);
        }
Exemplo n.º 12
0
        public void WriteDictionary(DictionaryAttribute attribute, object writer,
                                    object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            IDictionary       dict    = value.Convert <IDictionary>();
            DictionaryBuilder builder = writer.Convert <DictionaryBuilder>();
            QName             name    = info.QName;

            DictionaryBuilder subDict = builder.CreateBuilder();

            foreach (DictionaryEntry item in dict)
            {
                subDict.Add(item.Key.ToString(), ObjectUtil.ToString(info.Converter, item.Value, settings));
            }
            builder.Add(name.LocalName, subDict);
        }
Exemplo n.º 13
0
        public void WriteDictionary(DictionaryAttribute attribute, object writer,
                                    object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            var current = serializerData.Convert <XElement>();
            //XElement element = new XElement(info.QName.ToXName());
            //current.Add(element);
            IDictionary dict = value as IDictionary;

            if (dict != null)
            {
                foreach (DictionaryEntry item in dict)
                {
                    XElement subItem = new XElement(item.Key.ToString(),
                                                    ObjectUtil.ToString(info.Converter, item.Value, settings));
                    current.Add(subItem);
                }
            }
        }
Exemplo n.º 14
0
 public void WriteElement(SimpleElementAttribute attribute, object writer,
                          object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
 {
     if (attribute.IsMultiple)
     {
         IList         list    = value.Convert <IList>();
         List <string> strList = new List <string>(list.Count);
         foreach (object itemValue in list)
         {
             string item = ObjectUtil.ToString(info.Converter, itemValue, settings);
             strList.Add(item);
         }
         SetValue(writer, info.LocalName, strList);
     }
     else
     {
         SetValue(writer, info, info.LocalName, value, settings);
     }
 }
Exemplo n.º 15
0
        public void WriteDictionary(DictionaryAttribute attribute, object writer,
                                    object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlWriter   xmlWriter   = writer.Convert <XmlWriter>();
            PrefixTable prefixTable = serializerData.Convert <PrefixTable>();

            WriteStartElement(xmlWriter, info.QName, prefixTable);
            IDictionary dict = value as IDictionary;

            if (dict != null)
            {
                foreach (DictionaryEntry item in dict)
                {
                    xmlWriter.WriteStartElement(item.Key.ToString());
                    xmlWriter.WriteString(ObjectUtil.ToString(info.Converter, item.Value, settings));
                    xmlWriter.WriteEndElement();
                }
            }

            xmlWriter.WriteEndElement();
        }
Exemplo n.º 16
0
 private static void WriteSimpleJsonValue(JsonWriter jsonWriter, object value,
                                          WriteSettings settings, ObjectPropertyInfo info, bool useSourceType)
 {
     if (useSourceType)
     {
         if (value == null)
         {
             jsonWriter.WriteValue((string)null);
         }
         Type type = value.GetType();
         if (type.IsNullableType())
         {
             Type nestType = Nullable.GetUnderlyingType(type);
             value = Convert.ChangeType(value, nestType, ObjectUtil.SysCulture);
         }
         jsonWriter.WriteValue(value);
     }
     else
     {
         jsonWriter.WriteValue(ObjectUtil.ToString(info.Converter, value, settings));
     }
 }
Exemplo n.º 17
0
        public void WriteAttribute(SimpleAttributeAttribute attribute, object writer,
                                   object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (ObjectUtil.IsDefaultValue(attribute.DefaultValue, value))
            {
                return;
            }

            XmlWriter xmlWriter = writer.Convert <XmlWriter>();
            QName     name      = info.QName;

            if (name.HasNamespace)
            {
                PrefixTable prefix = serializerData.Convert <PrefixTable>();
                xmlWriter.WriteAttributeString(prefix.GetPrefix(name.Namespace), name.LocalName,
                                               name.Namespace, ObjectUtil.ToString(info.Converter, value, settings));
            }
            else
            {
                xmlWriter.WriteAttributeString(name.LocalName,
                                               ObjectUtil.ToString(info.Converter, value, settings));
            }
        }
Exemplo n.º 18
0
        public void WriteElement(SimpleElementAttribute attribute, object writer,
                                 object value, WriteSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (!attribute.IsMultiple && ObjectUtil.IsDefaultValue(attribute.DefaultValue, value))
            {
                return;
            }

            XmlWriter   xmlWriter   = writer.Convert <XmlWriter>();
            PrefixTable prefixTable = serializerData.Convert <PrefixTable>();

            WriteStartElement(xmlWriter, info.QName, prefixTable);
            string data = ObjectUtil.ToString(info.Converter, value, settings);

            if (attribute.UseCData)
            {
                xmlWriter.WriteCData(data);
            }
            else
            {
                xmlWriter.WriteString(data);
            }
            xmlWriter.WriteEndElement();
        }