예제 #1
0
        public static void ReadXml(this object receiver, string xml, ReadSettings settings, QName root)
        {
            TkDebug.AssertArgumentNull(root, "root", null);

            ReadFromString(receiver, "Xml", null, xml, settings, root);
        }
예제 #2
0
 public static string WriteXml(this object receiver, WriteSettings settings, QName root)
 {
     return(WriteXml(receiver, null, settings, root));
 }
예제 #3
0
        public static void ReadObject(IObjectSerializer serializer, object reader,
                                      object receiver, string modelName, ReadSettings settings, QName root,
                                      BaseObjectAttribute attribute, object serializerData, SerializerOptions options)
        {
            if (receiver is IDictionary)
            {
                BaseDictionaryAttribute attr = attribute as BaseDictionaryAttribute;
                options.CheckReadDictionary(serializer, attr);
                if (attr == null)
                {
                    attr = GetDictionaryAttribute(receiver, root);
                }

                serializer.ReadDictionary(reader, receiver.Convert <IDictionary>(), attr,
                                          modelName, settings, root, serializerData);
            }
            else if (receiver is IList)
            {
                SimpleElementAttribute attr = attribute as SimpleElementAttribute;
                options.CheckReadList(serializer, attr);
                if (attr == null)
                {
                    Type valueType = ObjectUtil.GetListValueType(receiver.GetType(), "", null);
                    attr = GetElementAttribute(receiver, valueType);
                }
                serializer.ReadList(reader, receiver.Convert <IList>(), attr, modelName,
                                    settings, root, serializerData);
            }
            else
            {
                options.CheckReadObject(serializer);
                serializer.ReadObject(reader, receiver, modelName, settings, root, serializerData);
            }
        }
예제 #4
0
        private static BaseDictionaryAttribute GetDictionaryAttribute(object receiver, QName root)
        {
            Type                    valueType = ObjectUtil.GetDictionaryValueType(receiver.GetType(), "", null);
            ITkTypeConverter        converter = TkTypeDescriptor.GetSimpleConverter(valueType);
            BaseDictionaryAttribute attr;

            if (converter == null)
            {
                attr = new ObjectDictionaryAttribute {
                    ObjectType = valueType
                }
            }
            ;
            else
            {
                attr = new DictionaryAttribute {
                    ObjectType = valueType
                }
            };

            attr.Assign(root);
            return(attr);
        }
예제 #5
0
 public bool ReadToRoot(object reader, QName root)
 {
     return(true);
 }
예제 #6
0
        public static void WriteObject(IObjectSerializer serializer, object writer,
                                       object receiver, string modelName, WriteSettings settings, QName root,
                                       BaseObjectAttribute attribute, object serializerData, SerializerOptions options)
        {
            Type type = receiver.GetType();

            if (receiver is IDictionary)
            {
                BaseDictionaryAttribute attr = attribute as BaseDictionaryAttribute;
                options.CheckWriteDictionary(serializer, attr);
                if (attr == null)
                {
                    attr = GetDictionaryAttribute(receiver, root);
                }
                serializer.WriteDictionary(writer, receiver.Convert <IDictionary>(), attr,
                                           modelName, settings, root, serializerData);
            }
            else if (type.IsArray || receiver is IList)
            {
                SimpleElementAttribute attr = attribute as SimpleElementAttribute;
                options.CheckWriteList(serializer, attr);
                if (attr == null)
                {
                    Type valueType;
                    if (type.IsArray)
                    {
                        Array arr = receiver as Array;
                        if (arr.Length == 0)
                        {
                            return;
                        }
                        var enumerator = arr.GetEnumerator();
                        enumerator.MoveNext();
                        valueType = enumerator.Current.GetType();
                    }
                    else
                    {
                        valueType = ObjectUtil.GetListValueType(type, "", null);
                    }
                    attr = GetElementAttribute(receiver, valueType);
                }
                serializer.WriteList(writer, receiver.Convert <IEnumerable>(), attr,
                                     modelName, settings, root, serializerData);
            }
            else
            {
                options.CheckWriteObject(serializer);
                ITkTypeConverter converter = TkTypeDescriptor.GetSimpleConverter(type);
                if (converter != null)
                {
                    SimpleElementAttribute simpleAttr = new SimpleElementAttribute
                    {
                        LocalName    = root.LocalName,
                        NamespaceUri = root.Namespace
                    };
                    var info = new SimpleObjectPropertyInfo(receiver, type, simpleAttr, converter);
                    serializer.WriteElement(simpleAttr, writer, receiver, settings, info, serializerData);
                }
                else
                {
                    serializer.WriteObject(writer, receiver, modelName, settings, root, serializerData);
                }
            }
        }
예제 #7
0
 public void WriteDictionary(object writer, IDictionary receiver, BaseDictionaryAttribute attribute,
                             string modelName, WriteSettings settings, QName root, object serializerData)
 {
     throw new NotSupportedException();
 }
예제 #8
0
 public static XDocument CreateXDocument(this object receiver, string modelName,
                                         WriteSettings settings, QName root)
 {
     return(receiver.CreateObject("XElement", modelName, settings, root).Convert <XElementData>().Root);
 }
예제 #9
0
 public void Write(object writer, object receiver, string modelName, WriteSettings settings,
                   QName root, object serializerData, BaseObjectAttribute attribute)
 {
     SerializerUtil.WriteObject(this, writer, receiver, modelName, settings,
                                root, attribute, null, Options);
 }
예제 #10
0
 public void WriteList(object writer, IEnumerable receiver, SimpleElementAttribute attribute,
                       string modelName, WriteSettings settings, QName root, object serializerData)
 {
     throw new NotSupportedException();
 }
예제 #11
0
 public void ReadList(object reader, IList receiver, SimpleElementAttribute attribute,
                      string modelName, ReadSettings settings, QName root, object serializerData)
 {
     throw new NotSupportedException();
 }
예제 #12
0
 public void ReadObject(object reader, object receiver, string modelName,
                        ReadSettings settings, QName root, object serializerData)
 {
     throw new NotSupportedException();
 }
예제 #13
0
 public void WriteObject(object writer, object receiver, string modelName,
                         WriteSettings settings, QName root, object serializerData)
 {
     SerializerUtil.Write(this, writer, receiver, modelName, settings);
 }
예제 #14
0
 public void Read(object reader, object receiver, string modelName, ReadSettings settings,
                  QName root, BaseObjectAttribute attribute)
 {
     SerializerUtil.ReadObject(this, reader, receiver, modelName, settings,
                               root, attribute, null, SerializerOptions.XmlOptions);
 }
예제 #15
0
 public object BeginWrite(object writer, object receiver, WriteSettings settings, QName root)
 {
     return(null);
 }
예제 #16
0
        public bool ReadToRoot(object reader, QName root)
        {
            XmlReader xmlreader = reader.Convert <XmlReader>();

            return(xmlreader.ReadToFollowing(root.LocalName, root.Namespace));
        }
예제 #17
0
 public static void ReadXmlFromFile(this object receiver, string fileName,
                                    ReadSettings settings, QName root)
 {
     ReadXmlFromFile(receiver, null, fileName, settings, root);
 }