Esempio n. 1
0
        private object ReadObject(bool usector, ReadSettings settings, JsonTextReader jsonReader,
                                  Type objectType, object receiver, string modelName)
        {
            object subObject = usector ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);

            //InternalRead(jsonReader, subObject, modelName, settings);
            //允许递归调用,内嵌的如果不是对象,是数组或者Dictionary,都支持了
            Read(jsonReader, subObject, modelName, settings, null, null);
            SerializerUtil.SetParent(receiver, subObject);
            return(subObject);
        }
Esempio n. 2
0
        public void ReadObjectElement(ObjectElementAttribute attribute, object reader,
                                      object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            Type   objectType = info.ObjectType;
            object subObject  = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);

            Read(reader, subObject, info.ModelName, settings, info.QName, null);
            SerializerUtil.SetParent(receiver, subObject);

            SerializerUtil.AddElementValue(attribute, receiver, info, subObject);
        }
Esempio n. 3
0
        public void ReadDynamicDictionary(DynamicDictionaryAttribute attribute, object reader,
                                          object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlReader xml = reader.Convert <XmlReader>();

            QName       name = info.QName;
            IDictionary dict = attribute.GetDictionary(receiver, info);

            if (xml.IsEmptyElement)
            {
                return;
            }
            var configData = attribute.PlugInFactory.ConfigData;
            //var propertyInfo = info.Convert<ReflectorObjectPropertyInfo>().Property;
            var elementReader = new ConfigFactoryElementReader(attribute, info, info.ModelName);

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.EndElement)
                {
                    QName nodeName = QName.Get(xml);
                    if (nodeName == name)
                    {
                        return;
                    }
                }

                if (xml.NodeType == XmlNodeType.Element)
                {
                    QName nodeName = QName.Get(xml);
                    ObjectPropertyInfo subPropertyInfo;
                    if (elementReader.SupportVersion)
                    {
                        string version = xml.GetAttribute(ToolkitConst.VERSION);
                        subPropertyInfo = elementReader[nodeName, version];
                    }
                    else
                    {
                        subPropertyInfo = elementReader[nodeName];
                    }
                    if (subPropertyInfo != null)
                    {
                        ObjectElementAttribute elementAttr = subPropertyInfo.Attribute.Convert <ObjectElementAttribute>();
                        Type   objectType = elementAttr.ObjectType;
                        object subObject  = elementAttr.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                            : ObjectUtil.CreateObject(objectType);
                        Read(reader, subObject, info.ModelName, settings, nodeName, null);
                        SerializerUtil.SetParent(receiver, subObject);
                        dict[nodeName.LocalName] = subObject;
                    }
                }
            }
        }
Esempio n. 4
0
        private static object ReadObject(bool usector, ReadSettings settings, DataRow row,
                                         Type objectType, object receiver, IObjectSerializer datarowSerializer, string modelName)
        {
            object subObject = usector ? ObjectUtil.CreateObjectWithCtor(objectType)
                : ObjectUtil.CreateObject(objectType);
            object rowReader = datarowSerializer.CreateCustomReader(row);

            datarowSerializer.ReadObject(rowReader, subObject, modelName, settings, QName.Toolkit, null);
            SerializerUtil.SetParent(receiver, subObject);

            return(subObject);
        }
Esempio n. 5
0
        public void ReadDynamicDictionary(DynamicDictionaryAttribute attribute, object reader,
                                          object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElementData currentData = reader.Convert <XElementData>();
            XElement     current     = currentData.Current;
            IDictionary  dict        = attribute.GetDictionary(receiver, info);
            var          configData  = attribute.PlugInFactory.ConfigData;
            //var propertyInfo = info.Convert<ReflectorObjectPropertyInfo>().Property;
            var elementReader = new ConfigFactoryElementReader(attribute, info, info.ModelName);

            foreach (XElement child in current.Elements())
            {
                string             nodeName = child.Name.LocalName;
                QName              qName    = child.Name.ToQName();
                ObjectPropertyInfo subPropertyInfo;
                if (elementReader.SupportVersion)
                {
                    var    verAttr = child.Attribute(ToolkitConst.VERSION);
                    string version = verAttr != null ? verAttr.Value : string.Empty;
                    subPropertyInfo = elementReader[nodeName, version];
                }
                else
                {
                    subPropertyInfo = elementReader[nodeName];
                }
                if (subPropertyInfo != null)
                {
                    ObjectElementAttribute elementAttr = subPropertyInfo.Attribute.Convert <ObjectElementAttribute>();
                    Type   objectType = elementAttr.ObjectType;
                    object subObject  = elementAttr.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                        : ObjectUtil.CreateObject(objectType);
                    XElementData next = new XElementData {
                        Current = child, Root = currentData.Root
                    };

                    Read(next, subObject, info.ModelName, settings, QName.Get(nodeName), null);
                    SerializerUtil.SetParent(receiver, subObject);
                    dict[nodeName] = subObject;
                }
            }
        }
Esempio n. 6
0
        public void ReadObjectDictionary(ObjectDictionaryAttribute attribute, object reader,
                                         object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlReader xml = reader.Convert <XmlReader>();

            QName       name       = info.QName;
            IDictionary dict       = attribute.GetDictionary(receiver, info);
            Type        objectType = info.ObjectType;

            if (xml.IsEmptyElement)
            {
                return;
            }

            while (xml.Read())
            {
                if (xml.NodeType == XmlNodeType.EndElement)
                {
                    QName nodeName = QName.Get(xml);
                    if (nodeName == name)
                    {
                        return;
                    }
                }

                if (xml.NodeType == XmlNodeType.Element)
                {
                    QName  nodeName  = QName.Get(xml);
                    object subObject = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                        : ObjectUtil.CreateObject(objectType);
                    Read(reader, subObject, info.ModelName, settings, nodeName, null);
                    SerializerUtil.SetParent(receiver, subObject);

                    //string nodeValue = ReadString(xml);
                    //object objValue = SerializerUtil.GetPropertyObject(receiver, settings,
                    //    info, nodeValue, objectType);
                    dict[nodeName.LocalName] = subObject;
                }
            }
        }
Esempio n. 7
0
        public void ReadObjectDictionary(ObjectDictionaryAttribute attribute, object reader,
                                         object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElementData currentData = reader.Convert <XElementData>();
            XElement     current     = currentData.Current;
            IDictionary  dict        = attribute.GetDictionary(receiver, info);
            Type         objectType  = info.ObjectType;

            foreach (XElement child in current.Elements())
            {
                string nodeName  = child.Name.LocalName;
                object subObject = attribute.UseConstructor ?
                                   ObjectUtil.CreateObjectWithCtor(objectType) : ObjectUtil.CreateObject(objectType);

                XElementData next = new XElementData {
                    Current = child, Root = currentData.Root
                };
                Read(next, subObject, info.ModelName, settings, QName.Get(nodeName), null);
                SerializerUtil.SetParent(receiver, subObject);
                dict[nodeName] = subObject;
            }
        }
Esempio n. 8
0
        public void ReadObjectElement(ObjectElementAttribute attribute, object reader, object receiver,
                                      ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (attribute.IsMultiple)
            {
                throw new NotSupportedException();
            }

            string xml = GetValue(reader, info.LocalName);

            if (string.IsNullOrEmpty(xml))
            {
                SerializerUtil.AddElementValue(attribute, receiver, info, null);
            }
            else
            {
                Type   objectType = info.ObjectType;
                object subObject  = attribute.UseConstructor ? ObjectUtil.CreateObjectWithCtor(objectType)
                    : ObjectUtil.CreateObject(objectType);
                subObject.ReadXml(xml, settings, QName.ToolkitNoNS);
                SerializerUtil.AddElementValue(attribute, receiver, info, subObject);
                SerializerUtil.SetParent(receiver, subObject);
            }
        }