public void ReadElement(SimpleElementAttribute attribute, object reader,
                                object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (attribute.IsMultiple)
            {
                QueryStringValue itemValue = GetValue(reader, info.LocalName);
                if (itemValue == null)
                {
                    return;
                }
                var itemValues = itemValue.Values;
                if (itemValues == null)
                {
                    return;
                }

                foreach (var item in itemValues)
                {
                    object objValue = SerializerUtil.GetPropertyObject(receiver, settings, info,
                                                                       item, attribute.AutoTrim);
                    SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
                }
            }
            else
            {
                SerializerUtil.SetObjectValue(receiver, settings, info,
                                              GetValue(reader, info.LocalName).ConvertToString(), attribute.AutoTrim);
            }
        }
Example #2
0
        private object GetSimpleValue(JsonTextReader reader, object receiver,
                                      ReadSettings settings, ObjectPropertyInfo info, bool autoTrim)
        {
            switch (reader.TokenType)
            {
            case JsonToken.Null:
            case JsonToken.Undefined:
                return(null);

            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.Boolean:
            case JsonToken.String:
                string value = reader.Value.ToString();
                return(SerializerUtil.GetPropertyObject(receiver, settings, info, value, autoTrim));

            case JsonToken.Date:
            case JsonToken.Bytes:
                return(reader.Value);

            default:
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "读取属性{3}时发生JSON错误。当前的状态是{0},不是有效的值状态,在第{1}行,第{2}列",
                                                            reader.TokenType, reader.CurrentLineNumber, reader.CurrentLinePosition,
                                                            info.PropertyName), this);
                return(null);
            }
        }
Example #3
0
        public void ReadComplexElement(SimpleComplexElementAttribute attribute, object reader,
                                       object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlReader xml      = reader.Convert <XmlReader>();
            string    value    = ReadComplexContent(xml, info.QName);
            object    objValue = SerializerUtil.GetPropertyObject(receiver, settings, info, value, false);

            SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
        }
Example #4
0
        public void ReadComplexElement(SimpleComplexElementAttribute attribute, object reader,
                                       object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElement current = XElementData.GetCurrent(reader);

            string value    = current.HasElements ? current.FirstNode.ToString() : null;
            object objValue = SerializerUtil.GetPropertyObject(receiver, settings, info, value, false);

            SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
        }
Example #5
0
        public void ReadElement(SimpleElementAttribute attribute, object reader,
                                object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XmlReader xml      = reader.Convert <XmlReader>();
            string    value    = ReadString(xml);
            object    objValue = SerializerUtil.GetPropertyObject(receiver, settings, info,
                                                                  value, attribute.AutoTrim);

            SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
        }
Example #6
0
        public void ReadElement(SimpleElementAttribute attribute, object reader,
                                object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElement current = XElementData.GetCurrent(reader);

            string value    = current.Value;
            object objValue = SerializerUtil.GetPropertyObject(receiver, settings, info,
                                                               value, attribute.AutoTrim);

            SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
        }
Example #7
0
        private object ReadComplexValue(object reader, object receiver,
                                        ReadSettings settings, ObjectPropertyInfo info)
        {
            JsonTextReader jsonReader = reader.Convert <JsonTextReader>();

            AssertRead(jsonReader);
            string strValue = ReadComplexContent(jsonReader);
            object value    = SerializerUtil.GetPropertyObject(receiver, settings, info, strValue, false);

            info.SetValue(receiver, value);

            return(value);
        }
Example #8
0
        public void ReadElement(SimpleElementAttribute attribute, object reader, object receiver,
                                ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            if (attribute.IsMultiple)
            {
                throw new NotSupportedException();
            }

            string value    = GetValue(reader, info.LocalName);
            object objValue = SerializerUtil.GetPropertyObject(receiver, settings, info,
                                                               value, attribute.AutoTrim);

            SerializerUtil.AddElementValue(attribute, receiver, info, objValue);
        }
        public void ReadDictionary(object reader, IDictionary receiver, BaseDictionaryAttribute attribute,
                                   string modelName, ReadSettings settings, QName root, object serializerData)
        {
            SerializerUtil.CheckSimpleDictionary(attribute, this);

            QueryStringBuilder builder = reader.Convert <QueryStringBuilder>();
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);
            DictionaryAttribute dictAttr = attribute.Convert <DictionaryAttribute>();

            foreach (string key in builder.AllKeys)
            {
                var    value    = builder[key];
                string strValue = value.ToString();
                receiver[key] = SerializerUtil.GetPropertyObject(receiver, settings,
                                                                 info, strValue, dictAttr.AutoTrim);
            }
        }
Example #10
0
        public void ReadDictionary(object reader, IDictionary receiver, BaseDictionaryAttribute attribute,
                                   string modelName, ReadSettings settings, QName root, object serializerData)
        {
            SerializerUtil.CheckSimpleDictionary(attribute, this);

            DataRow row = reader.Convert <DataRow>();
            DataColumnCollection cols = row.Table.Columns;
            var info = new DictionaryListObjectPropertyInfo(receiver, attribute, root);
            DictionaryAttribute dictAttr = attribute.Convert <DictionaryAttribute>();

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

                receiver[columnName] = SerializerUtil.GetPropertyObject(receiver, settings,
                                                                        info, GetValue(reader, columnName), dictAttr.AutoTrim);
            }
        }
Example #11
0
        public void ReadDictionary(DictionaryAttribute attribute, object reader,
                                   object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData)
        {
            XElement    current    = XElementData.GetCurrent(reader);
            IDictionary dict       = attribute.GetDictionary(receiver, info);
            Type        objectType = info.ObjectType;

            foreach (XElement child in current.Elements())
            {
                string nodeName  = child.Name.LocalName;
                string nodeValue = child.Value;
                if (attribute.AutoTrim && nodeValue != null)
                {
                    nodeValue = nodeValue.Trim();
                }
                object objValue = SerializerUtil.GetPropertyObject(receiver, settings, info, nodeValue, objectType);
                dict[nodeName] = objValue;
            }
        }
Example #12
0
        public void ReadDictionary(DictionaryAttribute 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);
                    string nodeValue = ReadString(xml);
                    if (attribute.AutoTrim && nodeValue != null)
                    {
                        nodeValue = nodeValue.Trim();
                    }
                    object objValue = SerializerUtil.GetPropertyObject(receiver, settings,
                                                                       info, nodeValue, objectType);
                    dict[nodeName.LocalName] = objValue;
                }
            }
        }