Esempio n. 1
0
        //private void InternalWriteXml(object writer, object receiver, string modelName,
        //    WriteSettings settings, PrefixTable prefixTable)
        //{
        //}

        private void InternalReadElement(XmlReader reader, object receiver, ReadSettings settings,
                                         QName root, ObjectElementInfo elements, string modelName)
        {
            while (reader.Read())
            {
                XmlNodeType nodeType = reader.NodeType;
                if (nodeType == XmlNodeType.EndElement)
                {
                    QName name = QName.Get(reader);
                    if (name == root)
                    {
                        break;
                    }
                }
                if (nodeType == XmlNodeType.Element)
                {
                    QName name = QName.Get(reader);
                    ObjectPropertyInfo element = elements.GetObjectPerpertyInfo(name,
                                                                                () => reader.GetAttribute(ToolkitConst.VERSION));
                    if (element != null)
                    {
                        element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                    }
                    else
                    {
                        element = SerializerUtil.CustomRead(receiver, name.LocalName, modelName,
                                                            () => reader.GetAttribute(ToolkitConst.VERSION));
                        if (element != null)
                        {
                            element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void InternalReadElement(XElementData reader, object receiver, ReadSettings settings,

                                         QName root, ObjectElementInfo elements, string modelName)
        {
            foreach (var item in reader.Current.Elements())
            {
                QName name = item.Name.ToQName();
                ObjectPropertyInfo element = elements.GetObjectPerpertyInfo(name,
                                                                            () => reader.Current.Attribute(ToolkitConst.VERSION).Value);
                if (element != null)
                {
                    XElementData next = new XElementData {
                        Current = item, Root = reader.Root
                    };
                    element.Attribute.ReadObject(this, next, receiver, settings, element, null);
                }
                else
                {
                    element = SerializerUtil.CustomRead(receiver, name.LocalName, modelName,
                                                        () => reader.Current.Attribute(ToolkitConst.VERSION).Value);
                    if (element != null)
                    {
                        element.Attribute.ReadObject(this, reader, receiver, settings, element, null);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void ReadProperty(IObjectSerializer serializer, object reader,
                                        object receiver, ReadSettings settings, ObjectInfo info, string localName, string modelName)
        {
            ObjectPropertyInfo property = info.GetAttribute(localName);

            if (property != null)
            {
                property.Attribute.ReadObject(serializer, reader, receiver, settings, property, null);
            }
            else
            {
                property = info.Elements[localName];
                if (property != null)
                {
                    property.Attribute.ReadObject(serializer, reader, receiver, settings, property, null);
                }
                else if (info.Content != null && localName == ObjectInfo.CONTENT_NAME)
                {
                    info.Content.Attribute.ReadObject(serializer, reader, receiver, settings, info.Content, null);
                }
                else
                {
                    property = SerializerUtil.CustomRead(receiver, localName, modelName, () => null);
                    if (property != null)
                    {
                        property.Attribute.ReadObject(serializer, reader, receiver, settings, property, null);
                    }
                }
            }
        }
Esempio n. 4
0
        private void InternalRead(JsonTextReader reader, object receiver, string modelName, ReadSettings settings)
        {
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }

            bool readElement = false;

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                AssertReadState(reader, JsonToken.PropertyName, null);
                string localName = reader.Value.Convert <string>();

                ObjectPropertyInfo property = info.GetAttribute(localName);
                if (property != null)
                {
                    property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                }
                else
                {
                    property = info.Elements[localName];
                    if (property != null)
                    {
                        readElement = true;
                        property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                    }
                    else
                    {
                        if (localName == CONTENT_NAME && info.Content != null)
                        {
                            property = info.Content;
                            property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                        }
                        else
                        {
                            property = SerializerUtil.CustomRead(receiver, localName, modelName, () => null);
                            if (property != null)
                            {
                                property.Attribute.ReadObject(this, reader, receiver, settings, property, null);
                            }
                            else
                            {
                                SkipProperty(reader);
                            }
                        }
                    }
                }
            }
            SerializerUtil.ReadObjectCallBack(receiver);

            if (readElement)
            {
                SerializerUtil.CheckElementRequired(info.Elements, receiver);
            }
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }