public void ReadDictionary(DictionaryAttribute attribute, object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData) { JsonTextReader jsonReader = reader.Convert <JsonTextReader>(); // 考虑支持多层次Dictionary读取,外层Object可能读取过,所以这里做判断对此进行屏蔽 2019.6.24 if (jsonReader.TokenType != JsonToken.StartObject) { AssertRead(jsonReader); } AssertReadState(jsonReader, JsonToken.StartObject, info.PropertyName); IDictionary dict = attribute.GetDictionary(receiver, info); while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndObject) { break; } AssertReadState(jsonReader, JsonToken.PropertyName, info.PropertyName); string name = jsonReader.Value.ToString(); AssertRead(jsonReader); object value = GetSimpleValue(jsonReader, receiver, settings, info, attribute.AutoTrim); dict[name] = value; } }
public void ReadDictionary(DictionaryAttribute attribute, object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData) { DataTable table = serializerData.Convert <DataTable>(); if (table.Rows.Count != 1) { return; } DataRow row = table.Rows[0]; IDictionary dict = attribute.GetDictionary(receiver, info); foreach (DataColumn column in table.Columns) { dict[column.ColumnName] = row[column]; } }
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; } }
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; } } }