Esempio n. 1
0
        public void ReadObject(object reader, object receiver, string modelName,
                               ReadSettings settings, QName root, object serializerData)
        {
            DataRow    row  = reader.Convert <DataRow>();
            ObjectInfo info = ObjectInfo.Create(receiver, modelName);

            if (info.IsObjectContext)
            {
                TkDebug.ThrowIfNoGlobalVariable();
                BaseGlobalVariable.Current.ObjectContext.Push(receiver);
            }
            DataColumnCollection cols = row.Table.Columns;

            foreach (DataColumn column in cols)
            {
                string columnName = column.ColumnName;

                SerializerUtil.ReadProperty(this, reader, receiver, settings,
                                            info, columnName, modelName);
            }
            SerializerUtil.ReadObjectCallBack(receiver);
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
Esempio n. 2
0
        public void ReadObject(object reader, object receiver, string modelName, ReadSettings settings,
                               QName root, object serializerData)
        {
            TkDebug.AssertArgumentNull(receiver, "receiver", this);
            TkDebug.AssertArgumentNull(settings, "settings", this);
            TkDebug.AssertArgumentNull(root, "root", this);

            XElementData currentData = reader.Convert <XElementData>();
            XElement     current     = currentData.Current;
            ObjectInfo   info        = ObjectInfo.Create(receiver, modelName);

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

            foreach (var item in info.Attributes)
            {
                item.Attribute.ReadObject(this, reader, receiver, settings, item, serializerData);
            }

            if (current.IsEmpty)
            {
                SerializerUtil.ReadObjectCallBack(receiver);
                if (info.IsObjectContext)
                {
                    BaseGlobalVariable.Current.ObjectContext.Pop();
                }
                return;
            }

            bool readElement = false;

            if (info.Content != null)
            {
                info.Content.Attribute.ReadObject(this, reader, receiver, settings,
                                                  info.Content, serializerData);
            }
            else
            {
                readElement = true;
                InternalReadElement(currentData, receiver, settings, root, info.Elements, modelName);
            }

            SerializerUtil.ReadObjectCallBack(receiver);
            if (readElement)
            {
                SerializerUtil.CheckElementRequired(info.Elements, receiver);
            }
            if (info.IsObjectContext)
            {
                BaseGlobalVariable.Current.ObjectContext.Pop();
            }
        }
        public void ReadObject(object reader, object receiver, string modelName,
                               ReadSettings settings, QName root, object serializerData)
        {
            QueryStringBuilder builder = reader.Convert <QueryStringBuilder>();
            ObjectInfo         info    = ObjectInfo.Create(receiver, modelName);

            foreach (string key in builder.AllKeys)
            {
                SerializerUtil.ReadProperty(this, reader, receiver, settings, info, key, modelName);
            }
            SerializerUtil.ReadObjectCallBack(receiver);
        }
Esempio n. 4
0
        public static void ReadFromDataRow(this object receiver, DataRow row, string modelName,
                                           ReadSettings settings)
        {
            TkDebug.AssertArgumentNull(receiver, "receiver", null);
            TkDebug.AssertArgumentNull(row, "row", null);
            TkDebug.AssertArgumentNull(settings, "settings", null);

            IObjectSerializer serializer = ObjectExtension.CreateSerializer("DataRow");
            object            reader     = serializer.CreateCustomReader(row);

            serializer.ReadObject(reader, receiver, modelName, settings, QName.Toolkit, null);
            SerializerUtil.ReadObjectCallBack(receiver);
        }
Esempio n. 5
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();
            }
        }